MongoDB added collation support in version 3.4, so that you can specify collation for a collection or a view, an index, or certain operations that support collation, such as find() and aggregate().
Collation Document Fields
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
Collation Document Fields
To use collation options other than the default, you can specify a Collation Document. It's made up of the following fields:
{locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
Set the Collation Property while building an index
You also have the option to explicitly set the Collation for an index while building it. For example, adding “index” on the name property of the test collection with locale ‘en’ and strength 2:
1
| db.test.createIndex( { name: 1}, { collation: { locale: 'en' , strength: 2 } }) |
No comments:
Post a Comment