How do I make this case insensitive? At the moment it works but only when the case matches.
var query = Query.Matches("Name", searchString);
How do I make this case insensitive? At the moment it works but only when the case matches.
var query = Query.Matches("Name", searchString);
You can store the names in all uppercase or lowercase, and convert your search query to the correct case. If you would like to persist the original casing, you can create an additional field for searching, in an all upper/lower case. Then convert your query to all upper/lower case, and query on the upper/lower case version of the field. This would perform much better than using a regex.
For example:
var query = Query.Matches("Name_Upper", searchString.ToUpper());
You can do this using regexes. The Mongo query would look like this:
find({"Name": {"$regex": searchString, "$options": "i"}})
In C# you would write it something like this:
Query.Matches("Name", new BsonDocument(new Dictionary<string, object> {
"$regex": searchString,
"$options": "i"
}));