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:
- A collection
- A view
- An index
- A specific operation like
insertOne
orupdateOne
.
Below is an example to use collation for an index.
db.tasks.createIndex({
name: 1
}, {
collation: {
locale: "fr"
}
})
Get hands-on with 1400+ tech skills courses.