Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4115

Query against strings (case insensitive)

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I am using the MongoDB C# client to construct queries like "Name > 'Aardvark'".  I can easily create a query that filters on strings case-sensitively, like this:

      return Builders<T>.Filter.Gt("Name", "Aardvark");

      I can't seem to find an option for comparing strings case insensitively.  If I was writing the query directly in MongoDB, the query would look like this:

      { $expr: { $gte: [ {{{ $strcasecmp: [ "$Name", "}}Aardvark"] }, }

      It seems like it should be possible to do this with the .Where() function, but that function only recognizes `obj => obj.Name.Equals("Aardvark", OrdinalIgnoreCase)`.  It doesn't seem to permit any comparisons.

      When I try the following, I get an error executing my query:

      return Builders<T>.Filter.Where(x => String.Compare(x.Name, "Aardvark", OrdinalIgnoreCase);

      Is there a better way to do this, or is this not implemented today?

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            ted@spence.net Theodore Spence
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: