[CSHARP-4092] Case-insensitive StartsWith/EndsWith generates incorrect MQL Created: 09/Mar/22  Updated: 28/Oct/23  Resolved: 15/Mar/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: 2.14.0
Fix Version/s: 2.15.1

Type: Bug Priority: Unknown
Reporter: James Kovacs Assignee: James Kovacs
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CSHARP-3615
Backwards Compatibility: Minor Change

 Description   

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] } })



 Comments   
Comment by Githook User [ 04/May/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: CSHARP-4090 / CSHARP-4092 (#750)

CSHARP-4090: Implement support for string.Contains(match, StringComparison).
CSHARP-4092: Fix case-insensitive StartsWith/EndsWith to generate correct MQL.
Branch: v2.15.x
https://github.com/mongodb/mongo-csharp-driver/commit/f8bc005a1c866e13ac044dbe28708186b4bc184f

Comment by Githook User [ 15/Mar/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: CSHARP-4090 / CSHARP-4092 (#750)

CSHARP-4090: Implement support for string.Contains(match, StringComparison).
CSHARP-4092: Fix case-insensitive StartsWith/EndsWith to generate correct MQL.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c8b95a34f282a76769890d335d35dd2f76659a42

Generated at Wed Feb 07 21:47:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.