We are trying to use the following to search a text using Regex. Here is our code:
string name = "jm😋"
var queryExpr = new BsonRegularExpression(name);
var filter = Builders<CurrentClass>.Filter.Regex(s => s.Name, queryExpr);
Upon running this one, we will received an error showing:
Regular expression is invalid: invalid UTF-8 string
We try to inspect the query that is being generated from that filter, and surprisingly it doesn't use the $regex syntax. Here is the generated query:
find({ "Name" : /jm😋/ })
We are expecting the $regex syntax like this one:
find({ "Name" :
})
This is a serious bug on the Regex Filter Builder on the c# Library. Is there a way to use the $regex filter in the Filter Builder strongly type? We want to avoid creating BSON document as possible since it is not strongly typed.
Using latest version of the c# Library: 2.13.1