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: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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: