I have installed the current development version 3.3.11 in order to test the case insensitive index that is apparently supported according to https://jira.mongodb.org/browse/SERVER-90. I have tried this from a mongo shell and a simple test database and it does seem to work.
Unfortunately, even though one specifies collation (and strength) during index creation, one must also specify the same collation params with .find
in order to get case insensitive matches. If collation is omitted from the query, index behaves in a case sensitive fashion.
Even the newest C# MongoDB driver (2.3.0-beta1) does not seem to support supplying collation params to a query. So even though I have upgraded the engine and database, C# driver, created the index with required collation, I cannot seem to get the results using the current driver.
Is there a "manual" way of supplying extra arguments to a query?
This is now possible in the newer version of the C# mongo driver (since 2.4.0).
For example, to query against a case-insensitive index:
IMongoCollection<SomeObject> someCollection;
var results = someCollection.Find<SomeObject>(x => x.name == someName,
new FindOptions() { Collation = new Collation("en", strength: CollationStrength.Secondary) } )
Notice that to enjoy the power of the index, you need to specify in the query the exact same collation parameter as specified when creating the index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With