Skip to content

Commit 537c1f1

Browse files
jmd-mongojeff-allen-mongo
authored andcommitted
DOCS-14795 update order numeric when possible
1 parent daf27bd commit 537c1f1

25 files changed

+82
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Starting in MongoDB 5.0, update operators process document fields with
2+
string-based names in lexicographic order. Fields with numeric names are
3+
processed in numeric order. See :ref:`Update Operators Behavior
4+
<update-operators-processing-order>` for details.

source/reference/operator/update.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ Specify the operator expression in a document of the form:
3333
Update Operators
3434
----------------
3535

36+
.. _update-operators-processing-order:
37+
38+
Behavior
39+
~~~~~~~~
40+
41+
Starting in MongoDB 5.0, update operators process document fields with
42+
string-based names in lexicographic order. Fields with numeric names are
43+
processed in numeric order.
44+
45+
In MongoDB 4.4 and earlier, update operators process all document fields
46+
in lexicographic order.
47+
48+
Consider this example :update:`$set` command:
49+
50+
.. code-block:: javascript
51+
52+
{ $set: { "a.2": <new value>, "a.10": <new value>, } }
53+
54+
In MongoDB 5.0 and later, ``"a.2"`` is processed before ``"a.10"``
55+
because ``2`` comes before ``10`` in numeric order.
56+
57+
In MongoDB 4.4 and earlier, ``"a.10"`` is processed before ``"a.2"``
58+
because ``10`` comes before ``2`` in lexicographic order.
59+
3660
Fields
3761
~~~~~~
3862

source/reference/operator/update/addToSet.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Definition
3030
Behavior
3131
--------
3232

33+
.. include:: /includes/fact-update-operator-processing-order.rst
34+
3335
:update:`$addToSet` only ensures that there are no duplicate items
3436
*added* to the set and does not affect existing duplicate elements.
3537
:update:`$addToSet` does not guarantee a particular ordering of

source/reference/operator/update/bit.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Behavior
4242

4343
.. include:: /includes/extracts/update-operation-empty-operand-expressions-bit.rst
4444

45+
.. include:: /includes/fact-update-operator-processing-order.rst
46+
4547
Examples
4648
--------
4749

source/reference/operator/update/currentDate.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Definition
4141
Behavior
4242
--------
4343

44+
.. include:: /includes/fact-update-operator-processing-order.rst
45+
4446
If the field does not exist, :update:`$currentDate` adds the field to a
4547
document.
4648

source/reference/operator/update/each.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Definition
3737
other modifiers. For a list of modifiers available for
3838
:update:`$push`, see :ref:`push-modifiers`.
3939

40+
Behavior
41+
--------
42+
43+
.. include:: /includes/fact-update-operator-processing-order.rst
44+
4045
Examples
4146
--------
4247

source/reference/operator/update/inc.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Definition
2727
Behavior
2828
--------
2929

30+
.. include:: /includes/fact-update-operator-processing-order.rst
31+
3032
The :update:`$inc` operator accepts positive and negative values.
3133

3234
If the field does not exist, :update:`$inc` creates the field and sets

source/reference/operator/update/max.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Definition
3232
Behavior
3333
--------
3434

35+
.. include:: /includes/fact-update-operator-processing-order.rst
36+
3537
If the field does not exists, the :update:`$max` operator sets the
3638
field to the specified value.
3739

source/reference/operator/update/min.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Definition
3030
Behavior
3131
--------
3232

33+
.. include:: /includes/fact-update-operator-processing-order.rst
34+
3335
If the field does not exist, the :update:`$min` operator sets the
3436
field to the specified value.
3537

source/reference/operator/update/mul.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Behavior
3131

3232
.. include:: /includes/extracts/update-operation-empty-operand-expressions-mul.rst
3333

34+
.. include:: /includes/fact-update-operator-processing-order.rst
35+
3436
Missing Field
3537
~~~~~~~~~~~~~
3638

0 commit comments

Comments
 (0)