Skip to content

Commit 9e97be2

Browse files
authored
Docsp-19919 add limitations to numeric ordering 4.0 (#350)
* DOCSP-19919 init * code-block none * *** * add 3 documents back to insert * numericOrder -> numericOrdering
1 parent 26d99d1 commit 9e97be2

File tree

2 files changed

+115
-20
lines changed

2 files changed

+115
-20
lines changed

source/includes/extracts-collation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ content: |
4343
4444
The collation option has the following syntax:
4545
46-
.. code-block:: javascript
46+
.. code-block:: none
4747
4848
collation: {
4949
locale: <string>,
@@ -62,7 +62,7 @@ content: |
6262
---
6363
ref: collation-document
6464
content: |
65-
.. code-block:: javascript
65+
.. code-block:: none
6666
6767
{
6868
locale: <string>,

source/reference/collation.txt

Lines changed: 113 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ parameters and the locales they are associated with, see
3535

3636
.. list-table::
3737
:header-rows: 1
38-
:widths: 20 20 80
38+
:widths: 25 20 80
3939

4040
* - Field
4141

@@ -66,7 +66,7 @@ parameters and the locales they are associated with, see
6666

6767
.. list-table::
6868
:header-rows: 1
69-
:widths: 10 90
69+
:widths: 15 90
7070

7171
* - Value
7272
- Description
@@ -119,10 +119,10 @@ parameters and the locales they are associated with, see
119119

120120
- boolean
121121

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``.
124124

125-
If ``true``, include case comparison; i.e.
125+
If ``true``, include case comparison:
126126

127127
- When used with ``strength:1``, collation compares base characters
128128
and case.
@@ -149,17 +149,18 @@ parameters and the locales they are associated with, see
149149

150150
.. list-table::
151151
:header-rows: 1
152-
:widths: 10 90
152+
:widths: 30 90
153153

154154
* - Value
155155
- Description
156-
* - "upper"
156+
157+
* - ``"upper"``
157158
- Uppercase sorts before lowercase.
158159

159-
* - "lower"
160+
* - ``"lower"``
160161
- Lowercase sorts before uppercase.
161162

162-
* - "off"
163+
* - ``"off"``
163164

164165
- Default value. Similar to ``"lower"`` with slight
165166
differences. See
@@ -175,12 +176,15 @@ parameters and the locales they are associated with, see
175176
- Optional. Flag that determines whether to compare numeric strings as numbers
176177
or as strings.
177178

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"``.
180181

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"``.
182184

183185
Default is ``false``.
186+
187+
See :ref:`numericOrdering Restrictions <numeric-order-restrictions>`.
184188

185189

186190

@@ -195,7 +199,7 @@ parameters and the locales they are associated with, see
195199

196200
.. list-table::
197201
:header-rows: 1
198-
:widths: 10 90
202+
:widths: 30 90
199203

200204
* - Value
201205
- Description
@@ -229,19 +233,19 @@ parameters and the locales they are associated with, see
229233

230234
.. list-table::
231235
:header-rows: 1
232-
:widths: 10 90
236+
:widths: 30 90
233237

234238
* - Value
235239
- Description
236240

237241
* - ``"punct"``
238242

239-
- Both whitespaces and punctuation are "ignorable", i.e. not
243+
- Both whitespace and punctuation are ignorable and not
240244
considered base characters.
241245

242246
* - ``"space"``
243247

244-
- Whitespace are "ignorable", i.e. not considered base
248+
- Whitespace is ignorable and not considered to be base
245249
characters.
246250

247251

@@ -278,7 +282,7 @@ parameters and the locales they are associated with, see
278282

279283
See
280284
`<http://userguide.icu-project.org/collation/concepts#TOC-Normalization>`_ for details.
281-
285+
282286

283287

284288

@@ -333,10 +337,101 @@ Collation and Unsupported Index Types
333337
.. include:: /includes/extracts/collation-index-type-restrictions.rst
334338

335339
.. 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
336409

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.
337432

338433
.. toctree::
339434
:titlesonly:
340435
:hidden:
341436

342-
/reference/collation-locales-defaults
437+
/reference/collation-locales-defaults

0 commit comments

Comments
 (0)