@@ -35,7 +35,7 @@ parameters and the locales they are associated with, see
35
35
36
36
.. list-table::
37
37
:header-rows: 1
38
- :widths: 20 20 80
38
+ :widths: 25 20 80
39
39
40
40
* - Field
41
41
@@ -66,7 +66,7 @@ parameters and the locales they are associated with, see
66
66
67
67
.. list-table::
68
68
:header-rows: 1
69
- :widths: 10 90
69
+ :widths: 15 90
70
70
71
71
* - Value
72
72
- Description
@@ -119,10 +119,10 @@ parameters and the locales they are associated with, see
119
119
120
120
- boolean
121
121
122
- - Optional. Flag that determines whether to include case comparison at
123
- ``strength`` level ``1`` or ``2``.
122
+ - Optional. Flag that determines whether to include case comparison
123
+ at ``strength`` level ``1`` or ``2``.
124
124
125
- If ``true``, include case comparison; i.e.
125
+ If ``true``, include case comparison:
126
126
127
127
- When used with ``strength:1``, collation compares base characters
128
128
and case.
@@ -149,17 +149,18 @@ parameters and the locales they are associated with, see
149
149
150
150
.. list-table::
151
151
:header-rows: 1
152
- :widths: 10 90
152
+ :widths: 30 90
153
153
154
154
* - Value
155
155
- Description
156
- * - "upper"
156
+
157
+ * - ``"upper"``
157
158
- Uppercase sorts before lowercase.
158
159
159
- * - "lower"
160
+ * - `` "lower"``
160
161
- Lowercase sorts before uppercase.
161
162
162
- * - "off"
163
+ * - `` "off"``
163
164
164
165
- Default value. Similar to ``"lower"`` with slight
165
166
differences. See
@@ -175,12 +176,15 @@ parameters and the locales they are associated with, see
175
176
- Optional. Flag that determines whether to compare numeric strings as numbers
176
177
or as strings.
177
178
178
- If ``true``, compare as numbers; i.e. ``"10"`` is greater than
179
- ``"2"``.
179
+ If ``true``, compare as numbers. For example,
180
+ ``"10"`` is greater than ``" 2"``.
180
181
181
- If ``false``, compare as strings; i.e. ``"10"`` is less than ``"2"``.
182
+ If ``false``, compare as strings. For example,
183
+ ``"10"`` is less than ``"2"``.
182
184
183
185
Default is ``false``.
186
+
187
+ See :ref:`numericOrdering Restrictions <numeric-order-restrictions>`.
184
188
185
189
186
190
@@ -195,7 +199,7 @@ parameters and the locales they are associated with, see
195
199
196
200
.. list-table::
197
201
:header-rows: 1
198
- :widths: 10 90
202
+ :widths: 30 90
199
203
200
204
* - Value
201
205
- Description
@@ -229,19 +233,19 @@ parameters and the locales they are associated with, see
229
233
230
234
.. list-table::
231
235
:header-rows: 1
232
- :widths: 10 90
236
+ :widths: 30 90
233
237
234
238
* - Value
235
239
- Description
236
240
237
241
* - ``"punct"``
238
242
239
- - Both whitespaces and punctuation are " ignorable", i.e. not
243
+ - Both whitespace and punctuation are ignorable and not
240
244
considered base characters.
241
245
242
246
* - ``"space"``
243
247
244
- - Whitespace are " ignorable", i.e. not considered base
248
+ - Whitespace is ignorable and not considered to be base
245
249
characters.
246
250
247
251
@@ -278,7 +282,7 @@ parameters and the locales they are associated with, see
278
282
279
283
See
280
284
`<http://userguide.icu-project.org/collation/concepts#TOC-Normalization>`_ for details.
281
-
285
+
282
286
283
287
284
288
@@ -333,10 +337,101 @@ Collation and Unsupported Index Types
333
337
.. include:: /includes/extracts/collation-index-type-restrictions.rst
334
338
335
339
.. include:: /includes/extracts/collation-index-type-restrictions-addendum.rst
340
+
341
+ Restrictions
342
+ ------------
343
+
344
+ .. _numeric-order-restrictions:
345
+
346
+ numericOrdering
347
+ ~~~~~~~~~~~~~~~
348
+
349
+ When specifying the ``numericOrdering`` as ``true`` the following
350
+ restrictions apply:
351
+
352
+ - Only contiguous non-negative integer substrings of digits are
353
+ considered in the comparisons.
354
+
355
+ ``numericOrdering`` does not support:
356
+
357
+ - ``+``
358
+ - ``-``
359
+ - decimal separators, like decimal points and decimal commas
360
+ - exponents
361
+
362
+ - Only Unicode code points in the Number or Decimal Digit (Nd) category
363
+ are treated as digits.
364
+
365
+ - If a digit length exceeds 254 characters, the excess characters are
366
+ treated as a separate number.
367
+
368
+ Consider a collection with the following string number and decimal
369
+ values:
370
+
371
+ .. code-block:: javascript
372
+ :emphasize-lines: 6,10
373
+
374
+ db.c.insertMany(
375
+ [
376
+ { "n" : "1" },
377
+ { "n" : "2" },
378
+ { "n" : "2.1" },
379
+ { "n" : "-2.1" },
380
+ { "n" : "2.2" },
381
+ { "n" : "2.10" },
382
+ { "n" : "2.20" },
383
+ { "n" : "-10" },
384
+ { "n" : "10" },
385
+ { "n" : "20" },
386
+ { "n" : "20.1" }
387
+ ]
388
+ )
389
+
390
+ The following :method:`find <db.collection.find()>` query uses a
391
+ collation document containing the ``numericOrdering`` parameter:
392
+
393
+ .. code-block:: javascript
394
+
395
+ db.c.find(
396
+ { }, { _id: 0 }
397
+ ).sort(
398
+ { n: 1 }
399
+ ).collation( {
400
+ locale: 'en_US',
401
+ numericOrdering: true
402
+ } )
403
+
404
+ The operation returns the following results:
405
+
406
+ .. code-block:: javascript
407
+ :emphasize-lines: 2-3,7-8
408
+ :copyable: false
336
409
410
+ [
411
+ { n: '-2.1' },
412
+ { n: '-10' },
413
+ { n: '1' },
414
+ { n: '2' },
415
+ { n: '2.1' },
416
+ { n: '2.2' },
417
+ { n: '2.10' },
418
+ { n: '2.20' },
419
+ { n: '10' },
420
+ { n: '20' },
421
+ { n: '20.1' }
422
+ ]
423
+
424
+ - ``numericOrdering: true`` sorts the string values in ascending
425
+ order as if they were numeric values.
426
+ - The two negative values ``-2.1`` and ``-10`` are not sorted in the
427
+ expected sort order because they have unsupported ``-`` characters.
428
+ - The value ``2.2`` is sorted before the value ``2.10``, due to the fact
429
+ that the ``numericOrdering`` parameter does not support decimal
430
+ values.
431
+ - As a result, ``2.2`` and ``2.10`` are sorted in lexicographic order.
337
432
338
433
.. toctree::
339
434
:titlesonly:
340
435
:hidden:
341
436
342
- /reference/collation-locales-defaults
437
+ /reference/collation-locales-defaults
0 commit comments