Bulk.find.collation()
On this page
Description
Bulk.find.collation(<document>)
Specifies the collation for the bulk writes. Append to
Bulk.find()
method to specify collation for the find operation.The
Bulk.find.collation()
accepts the following collation document:{ locale: <string>, caseLevel: <boolean>, caseFirst: <string>, strength: <int>, numericOrdering: <boolean>, alternate: <string>, maxVariable: <string>, backwards: <boolean> } When specifying collation, the
locale
field is mandatory; all other collation fields are optional. For descriptions of the fields, see Collation Document.FieldTypeDescriptionlocale
stringThe ICU locale. See Supported Languages and Locales for a list of supported locales.
To specify simple binary comparison, specify
locale
value of"simple"
.strength
integerOptional. The level of comparison to perform. Corresponds to ICU Comparison Levels. Possible values are:
ValueDescription1Primary level of comparison. Collation performs comparisons of the base characters only, ignoring other differences such as diacritics and case.2Secondary level of comparison. Collation performs comparisons up to secondary differences, such as diacritics. That is, collation performs comparisons of base characters (primary differences) and diacritics (secondary differences). Differences between base characters takes precedence over secondary differences.3Tertiary level of comparison. Collation performs comparisons up to tertiary differences, such as case and letter variants. That is, collation performs comparisons of base characters (primary differences), diacritics (secondary differences), and case and variants (tertiary differences). Differences between base characters takes precedence over secondary differences, which takes precedence over tertiary differences.
This is the default level.
4Quaternary Level. Limited for specific use case to consider punctuation when levels 1-3 ignore punctuation or for processing Japanese text.5Identical Level. Limited for specific use case of tie breaker.See ICU Collation: Comparison Levels for details.
caseLevel
booleanOptional. Flag that determines whether to include case comparison at
strength
level1
or2
.If
true
, include case comparison; i.e.When used with
strength:1
, collation compares base characters and case.When used with
strength:2
, collation compares base characters, diacritics (and possible other secondary differences) and case.
If
false
, do not include case comparison at level1
or2
. The default isfalse
.For more information, see ICU Collation: Case Level.
caseFirst
stringOptional. A field that determines sort order of case differences during tertiary level comparisons.
Possible values are:
ValueDescription"upper"Uppercase sorts before lowercase."lower"Lowercase sorts before uppercase."off"Default value. Similar to"lower"
with slight differences. See https://unicode-org.github.io/icu/userguide/strings/properties.html#customization for details of differences.numericOrdering
booleanOptional. Flag that determines whether to compare numeric strings as numbers or as strings.
If
true
, compare as numbers; i.e."10"
is greater than"2"
.If
false
, compare as strings; i.e."10"
is less than"2"
.Default is
false
.alternate
stringOptional. Field that determines whether collation should consider whitespace and punctuation as base characters for purposes of comparison.
Possible values are:
ValueDescription"non-ignorable"
Whitespace and punctuation are considered base characters."shifted"
Whitespace and punctuation are not considered base characters and are only distinguished at strength levels greater than 3.See ICU Collation: Comparison Levels for more information.
Default is
"non-ignorable"
.maxVariable
stringOptional. Field that determines up to which characters are considered ignorable when
alternate: "shifted"
. Has no effect ifalternate: "non-ignorable"
Possible values are:
ValueDescription"punct"
Both whitespaces and punctuation are "ignorable", i.e. not considered base characters."space"
Whitespace are "ignorable", i.e. not considered base characters.backwards
booleanOptional. Flag that determines whether strings with diacritics sort from back of the string, such as with some French dictionary ordering.
If
true
, compare from back to front.If
false
, compare from front to back.The default value is
false
.normalization
booleanOptional. Flag that determines whether to check if text require normalization and to perform normalization. Generally, majority of text does not require this normalization processing.
If
true
, check if fully normalized and perform normalization to compare text.If
false
, does not check.The default value is
false
.See https://unicode-org.github.io/icu/userguide/collation/concepts.html#normalization for details.
Example
The following example initializes a Bulk()
operations builder
for the myColl
collection and specifies a collation for the find
filter.
var bulk = db.myColl.initializeUnorderedBulkOp(); bulk.find( { category: "cafe" } ).collation({ locale: "fr", strength: 1 }).update( { $set: { status: "I", points: "0" } } ); bulk.execute();