8

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?

wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
  • Most of the MongoDB drivers will have support for 3.4 out in an RC release by mid-september. If you'd like a particular collation to be used on a collection in every query/index creation, you can set it as the default collation for the collection. Otherwise, you're going to need to specify the collation to use for every operation you do. – Craig Wilson Aug 25 '16 at 12:27
  • Thanks so much. You might post is an answer too. Can I modify my collection to support this now that it's holding millions of documents? – wpfwannabe Aug 25 '16 at 13:17
  • Yes, but your _id index won't change (and cannot) and any indices you have already created will continue to use the collation from when they were created. You can change it using the $collMod operator, although there aren't any docs and I've never done it before. – Craig Wilson Aug 25 '16 at 14:00

1 Answers1

13

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.

Y.L
  • 694
  • 12
  • 26
  • 2
    not working for Turkish collation. Because in Turkish there is a letter İ; dot with I and it is an exception for ASCII table. – Can PERK Aug 01 '19 at 12:39
  • @CanPERK are you sure that the index collation is also tr? İ and i should form a case-insensitive pair. If this does not work in the Primary or Secondary collation strengh for the `tr` locale, a bug should be filed. – Cee McSharpface Oct 28 '22 at 16:00