@@ -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.
@@ -176,12 +176,15 @@ parameters and the locales they are associated with, see
176
176
- Optional. Flag that determines whether to compare numeric strings as numbers
177
177
or as strings.
178
178
179
- If ``true``, compare as numbers; i.e. ``"10"`` is greater than
180
- ``"2"``.
179
+ If ``true``, compare as numbers. For example,
180
+ ``"10"`` is greater than ``" 2"``.
181
181
182
- 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"``.
183
184
184
185
Default is ``false``.
186
+
187
+ See :ref:`numericOrdering Restrictions <numeric-order-restrictions>`.
185
188
186
189
187
190
@@ -237,12 +240,12 @@ parameters and the locales they are associated with, see
237
240
238
241
* - ``"punct"``
239
242
240
- - Both whitespace and punctuation are " ignorable", i.e. not
243
+ - Both whitespace and punctuation are ignorable and not
241
244
considered base characters.
242
245
243
246
* - ``"space"``
244
247
245
- - Whitespace are " ignorable", i.e. not considered base
248
+ - Whitespace is ignorable and not considered to be base
246
249
characters.
247
250
248
251
@@ -334,7 +337,98 @@ Collation and Unsupported Index Types
334
337
.. include:: /includes/extracts/collation-index-type-restrictions.rst
335
338
336
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
337
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.
338
432
339
433
.. toctree::
340
434
:titlesonly:
0 commit comments