Collation and Hint

Learn the use of the collation and the $hint operator.

We'll cover the following

Collation

Collation is used when we need to specify language-specific rules for string comparison. The collation can be specified for any collection or operation that supports collation.

Syntax:

{
  "locale": <string> // Required
}

A collation can be used with:

  1. A collection
  2. A view
  3. An index
  4. A specific operation like insertOne or updateOne.

Below is an example to use collation for an index.

db.tasks.createIndex({ 
    name: 1 
}, { 
    collation: { 
        locale: "fr"
    }
})

Get hands-on with 1200+ tech skills courses.