November 2017
Intermediate to advanced
342 pages
9h 9m
English
Case sensitivity is a common use case for indexes. Up until version 3.4, this was dealt with at the application level by creating duplicate fields with all lowercase characters and indexing this field to simulate a case-insensitive index.
Using the collation parameter, we can create case-insensitive indexes and even collections that behave as case-insensitive.
Collation in general allows users to specify language-specific rules for string comparison. A possible (but not the only) usage is for case-insensitive indexes and queries.
Using our familiar books collection, we can create a case-insensitive index on a name like this:
> db.books.createIndex( { "name" : 1 }, { collation: { locale : 'en', strength : 1 } } )
strength ...
Read now
Unlock full access