Skip to content

DOCS-13822 permit empty update modifiers #5049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/includes/extracts-update-operations-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ref: _update-operation-empty-operand-expressions
content: |
Starting in MongoDB 5.0, :binary:`~bin.mongod` no longer raises an
error when you use an update operator like :update:`${{operator}}`
with an empty operand expression ( ``{ }`` ). An empty update results
in no changes and no :term:`oplog` entry is created (meaning that the
operation is a no-op).
105 changes: 105 additions & 0 deletions source/includes/extracts-update-operations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
ref: update-operation-empty-operand-expressions-add-to-set
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: addToSet
---
ref: update-operation-empty-operand-expressions-bit
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: bit
---
ref: update-operation-empty-operand-expressions-current-date
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: currentDate
---
ref: update-operation-empty-operand-expressions-inc
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: inc
---
ref: update-operation-empty-operand-expressions-max
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: max
---
ref: update-operation-empty-operand-expressions-min
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: min
---
ref: update-operation-empty-operand-expressions-mul
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: mul
---
ref: update-operation-empty-operand-expressions-pop
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: pop
---
ref: update-operation-empty-operand-expressions-pull
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: pull
---
ref: update-operation-empty-operand-expressions-pull-all
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: pullAll
---
ref: update-operation-empty-operand-expressions-push
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: push
---
ref: update-operation-empty-operand-expressions-rename
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: rename
---
ref: update-operation-empty-operand-expressions-set
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: set
---
ref: update-operation-empty-operand-expressions-set-on-insert
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: setOnInsert
---
ref: update-operation-empty-operand-expressions-unset
source:
file: extracts-update-operations-base.yaml
ref: _update-operation-empty-operand-expressions
replacement:
operator: unset
...
2 changes: 2 additions & 0 deletions source/reference/operator/update/addToSet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Behavior
:update:`$addToSet` does not guarantee a particular ordering of
elements in the modified set.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-add-to-set.rst

Missing Field
~~~~~~~~~~~~~

Expand Down
5 changes: 5 additions & 0 deletions source/reference/operator/update/bit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Definition
constructor to specify integers. See :ref:`shell-type-int` or
:ref:`shell-type-long` for more information.

Behavior
--------

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

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/currentDate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Behavior
If the field does not exist, :update:`$currentDate` adds the field to a
document.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-current-date.rst

Example
-------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/inc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ generate an error.

:update:`$inc` is an atomic operation within a single document.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-inc.rst

Example
-------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/max.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Behavior
If the field does not exists, the :update:`$max` operator sets the
field to the specified value.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-max.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/min.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ For comparisons between values of different types, such as a number and
a null, :update:`$min` uses the :ref:`BSON comparison order
<faq-dev-compare-order-for-BSON-types>`.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-min.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/mul.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Definition
Behavior
--------

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

Missing Field
~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/pop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The :update:`$pop` operation fails if the ``<field>`` is not an array.
If the :update:`$pop` operator removes the last item in the
``<field>``, the ``<field>`` will then hold an empty array.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-pop.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/pull.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ If the specified ``<value>`` to remove is a document, :update:`$pull`
removes only the elements in the array that have the exact same fields
and values. The ordering of the fields can differ.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-pull.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/pullAll.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ If a ``<value>`` to remove is a document or an array,
:update:`$pullAll` removes only the elements in the array that match
the specified ``<value>`` exactly, including order.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-pull-all.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/push.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ If the value is an array, :update:`$push` appends the whole array as a
:ref:`example-push-each`. For a list of modifiers available for
:update:`$push`, see :ref:`push-modifiers`.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-push.rst

.. _push-modifiers:

Modifiers
Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/rename.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ rename these fields as well as move the fields in and out of embedded
documents. :update:`$rename` does not work if these fields are in array
elements.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-rename.rst

Examples
--------

Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/set.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fulfill the dotted path to the field.
If you specify multiple field-value pairs, :update:`$set` will update
or create each field.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-set.rst

Examples
--------

Expand Down
7 changes: 6 additions & 1 deletion source/reference/operator/update/setOnInsert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ Definition

.. include:: /includes/use-dot-notation.rst

Example
Behavior
--------

.. include:: /includes/extracts/update-operation-empty-operand-expressions-set-on-insert.rst

Example
-------

A collection named ``products`` contains no documents.

Then, the following :method:`db.collection.update()` with :ref:`upsert:
Expand Down
2 changes: 2 additions & 0 deletions source/reference/operator/update/unset.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ replaces the matching element with ``null`` rather than removing the
matching element from the array. This behavior keeps consistent the
array size and element positions.

.. include:: /includes/extracts/update-operation-empty-operand-expressions-unset.rst

Example
-------

Expand Down
26 changes: 26 additions & 0 deletions source/release-notes/5.0-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ Read Concern `Snapshot` on Capped Collections

.. include:: /includes/extracts/transactions-capped-collection-read-change.rst

Update Operator Changes
-----------------------

Starting in MongoDB 5.0, :binary:`~bin.mongod` no longer raises
an error when you use the following update operators with an empty
operand expression ( ``{ }`` ):

- :update:`$addToSet`
- :update:`$bit`
- :update:`$currentDate`
- :update:`$inc`
- :update:`$max`
- :update:`$min`
- :update:`$mul`
- :update:`$pop`
- :update:`$pull`
- :update:`$pullAll`
- :update:`$push`
- :update:`$rename`
- :update:`$set`
- :update:`$setOnInsert`
- :update:`$unset`

An empty update results in no changes and no :term:`oplog` entry is
created (meaning that the operation is a no-op).

General Changes
---------------

Expand Down