Is it normal that a simple regex search is transformed to use the aggregation pipeline?
Hi Marc,
I tried to reproduce this with MongoDB .NET/C# driver v2.9.2, and unable to. How do you use the filters variable ?
The following example code:
var filter = Builders<BsonDocument>.Filter.Regex("Title", new BsonRegularExpression("TEST", "i"));
var results = collection.Find(filter).ToList();
Showed up in profiler as:
"op": "query",
"ns": "dbname.collname",
"command": {
"find": "collname",
"filter": {
"Title": /TEST/i
},
Also, if you’re using regex just for the case insensitive search, you can try to use case-insensitive index instead. For example:
var results = collection.Find<SomeObject>(x=>x.Title == "TEST", new FindOptions() {Collation = new Collation("en", strength: CollationStrength.Secondary)}).ToList();
If you have follow up questions, could you please provide:
filters variable. Regards,
Wan.
Hi Marc,
It would be helpful if you can provide:
Using the code example that I’ve posted above, I’m unable to reproduce the issue that you’re getting (The change of Find to aggregation match). If the code snippet is using the proper UTF-8 encoding (emoji), MongoCommandException will throw Regular expression is invalid: invalid UTF-8 string although you must have escaped this as based on your post you don’t seem to have this issue.
Regards,
Wan.