You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The flags for `$caseSensitive` and `$diacriticSensitive` can be set via the according methods on `TextCriteria`. Please note that these two optional flags have been introduced in MongoDB 3.2 and will not be included in the query unless explicitly set.
1346
1346
1347
+
[[mongo.collation]]
1348
+
=== Collations
1349
+
1350
+
MongoDB supports since 3.4 collations for collection and index creation and various query operations. Collations define string comparison rules based on the http://userguide.icu-project.org/collation/concepts[ICU collations]. A collation document consists of various properties that are encapsulated in `Collation`:
1351
+
1352
+
====
1353
+
[source,java]
1354
+
----
1355
+
Collation collation = Collation.of("fr") <1>
1356
+
1357
+
.strength(ComparisonLevel.secondary() <2>
1358
+
.includeCase())
1359
+
1360
+
.numericOrderingEnabled() <3>
1361
+
1362
+
.alternate(Alternate.shifted().punct()) <4>
1363
+
1364
+
.forwardDiacriticSort() <5>
1365
+
1366
+
.normalizationEnabled(); <6>
1367
+
----
1368
+
<1> `Collation` requires a locale for creation. This can be either a string representation of the locale, a `Locale` (considering language, country and variant) or a `CollationLocale`. The locale is mandatory for creation.
1369
+
<2> Collation strength defines comparison levels denoting differences between characters. You can configure various options (case-sensitivity, case-ordering) depending on the selected strength.
1370
+
<3> Specify whether to compare numeric strings as numbers or as strings.
1371
+
<4> Specify whether the collation should consider whitespace and punctuation as base characters for purposes of comparison.
1372
+
<5> Specify whether strings with diacritics sort from back of the string, such as with some French dictionary ordering.
1373
+
<6> Specify whether to check if text requires normalization and to perform normalization.
1374
+
====
1375
+
1376
+
Collations can be used to create collections and indexes. If you create a collection specifying a collation, the collation is applied to index creation and queries unless you specify a different collation. A collation is valid for a whole operation and cannot be specified on a per-field basis.
0 commit comments