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

Case-insensitive StartsWith/EndsWith generates incorrect MQL

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.15.1
    • Affects Version/s: 2.14.0
    • Component/s: LINQ3
    • Labels:
      None
    • Minor Change

      Repro:

      using MongoDB.Bson;
      using MongoDB.Driver;
      using MongoDB.Driver.Linq;
      
      var settings = new MongoClientSettings { LinqProvider = LinqProvider.V3 };
      var client = new MongoClient(settings);
      var db = client.GetDatabase("test");
      var coll = db.GetCollection<C>("coll");
      
      var query = coll.Find(x => x.Text.StartsWith(x.Match, StringComparison.CurrentCultureIgnoreCase));
      Console.WriteLine(query);
      
      record C(ObjectId Id, string Text, string Match);
      

      Output:

      find({ "$expr" : { "$eq" : [{ "$indexOfCP" : [{ "$toLower" : "$Text" }, { "$toLower" : { "$toLower" : "$Text" } }] }, 0] } })
      

      The correct MQL should be:

      find({ "$expr" : { "$eq" : [{ "$indexOfCP" : [{ "$toLower" : "$Text" }, { "$toLower" : "$Match" }] }, 0] } })
      

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: