Skip to content

Commit 9200afe

Browse files
jmd-mongojeff-allen-mongo
authored andcommitted
DOCS-14472 update operators act in lexicographic order
1 parent 1de1828 commit 9200afe

24 files changed

+84
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In MongoDB 4.4 and earlier, update operators process document fields
2+
in lexicographic order. See :ref:`Update Operators Behavior
3+
<update-operators-lexicographic-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-lexicographic-order:
37+
38+
Behavior
39+
~~~~~~~~
40+
41+
In MongoDB 4.4 and earlier, update operators process all document fields
42+
in lexicographic order.
43+
44+
In MongoDB 5.0 and later, update operators process document fields with
45+
string-based names in lexicographic order. Fields with numeric names are
46+
processed in numeric 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 4.4, ``"a.10"`` is processed before ``"a.2"`` because ``10``
55+
comes before ``2`` in lexicographic order.
56+
57+
In MongoDB 5.0, ``"a.2"`` is processed before ``"a.10"`` because ``2``
58+
comes before ``10`` in numeric 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-lexicographic-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Definition
3737
constructor to specify integers. See :ref:`shell-type-int` or
3838
:ref:`shell-type-long` for more information.
3939

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

source/reference/operator/update/currentDate.txt

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

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

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-lexicographic-order.rst
44+
4045
Examples
4146
--------
4247

source/reference/operator/update/inc.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ Definition
2323
{ $inc: { <field1>: <amount1>, <field2>: <amount2>, ... } }
2424

2525
.. include:: /includes/use-dot-notation.rst
26-
26+
2727
Behavior
2828
--------
2929

30+
.. include:: /includes/fact-update-operator-lexicographic-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-lexicographic-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Definition
3030
Behavior
3131
--------
3232

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

3638
For comparisons between values of different types, such as a number and

source/reference/operator/update/mul.txt

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

32+
.. include:: /includes/fact-update-operator-lexicographic-order.rst
33+
3234
Missing Field
3335
~~~~~~~~~~~~~
3436

0 commit comments

Comments
 (0)