Skip to content

V5.0.4 #6147

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 4 commits into from
Nov 16, 2021
Merged

V5.0.4 #6147

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
33 changes: 33 additions & 0 deletions source/includes/fact-validate-metadata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
*Optional*. A flag which allows users to perform a quick validation to
detect invalid index options without scanning all of the documents and
indexes.

- If ``true``, a metadata validation scan is performed.

- If ``false``, no metadata validation scan is not performed.

The default is ``false``.

Running the validate command with ``{ metadata: true }`` is not
supported with any other :dbcommand:`validate` options.

The ``metadata`` validation option:

- Provides you a faster way of identifying invalid indexes by scanning
only collections metadata.

- Provides an alternative to dropping and recreating multiple invalid
indexes when used with the :doc:`collMod </reference/command/collMod>`
command.

The ``metadata`` validation option only scans collection metadata to
find invalid indexes more quickly.

If there is an invalid index detected, the validate command will prompt
you to use the :dbcommand:`collMod` command to remove invalid indexes.

.. code-block:: javascript

db.runCommand( { collMod: <collectionName> } )

.. versionadded:: 5.0.4
5 changes: 3 additions & 2 deletions source/includes/fact-validate-repair-option.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ The repair fixes these issues:
- If corrupt documents with invalid BSON data are found, the documents
are removed.

.. seealso:: :option:`--repair <mongod --repair>` option for
:binary:`~bin.mongod`
.. seealso::

:option:`--repair <mongod --repair>` option for :binary:`~bin.mongod`

.. versionadded:: 5.0
16 changes: 15 additions & 1 deletion source/reference/command/validate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ The command has the following syntax:
db.runCommand( {
validate: <string>, // Collection name
full: <boolean>, // Optional
repair: <boolean> // Optional, added in MongoDB 5.0
repair: <boolean>, // Optional, added in MongoDB 5.0
metadata: <boolean> // Optional, added in MongoDB 5.0.4
} )

:binary:`~bin.mongosh` also provides a wrapper
Expand Down Expand Up @@ -96,6 +97,12 @@ The command takes the following fields:

.. include:: /includes/fact-validate-repair-option.rst

* - :ref:`metadata <cmd-validate-metadata>`
- boolean

- .. _cmd-validate-metadata:

.. include:: /includes/fact-validate-metadata.rst

Behavior
--------
Expand Down Expand Up @@ -159,6 +166,13 @@ Examples

db.runCommand( { validate: "myCollection", repair: true } )

- To validate the metadata in the ``myCollection`` collection,
specify :ref:`meta data: true <cmd-validate-metadata>`:

.. code-block:: javascript

db.runCommand( { validate: "myCollection", metadata: true } )

.. _validate-output:

Validate Output
Expand Down
6 changes: 6 additions & 0 deletions source/reference/operator/aggregation/setWindowFields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ Restrictions

Restrictions for the :pipeline:`$setWindowFields` stage:

- Starting in MongoDB 5.0.4, the :pipeline:`$setWindowFields`
stage cannot be used:

- Within :doc:`transactions </core/transactions>`.
- With :readconcern:`"snapshot"` read concern.

- :ref:`sortBy <setWindowFields-sortBy>` is required for:

- :ref:`Rank <setWindowFields-rank-operators>` and :ref:`order
Expand Down
54 changes: 35 additions & 19 deletions source/reference/operator/query/mod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,38 @@ $mod

{ field: { $mod: [ divisor, remainder ] } }

The :query:`$mod` operator errors when passed an array with fewer
or more than two elements. See :ref:`mod-not-enough-elements` and
:ref:`mod-too-many-elements` for details.
.. _mod-behavior:

Behavior
--------

The :query:`$mod` operator returns an error if the ``[ divisor,
remainder ]`` array contains fewer or more than two elements. For
examples, see :ref:`mod-not-enough-elements` and
:ref:`mod-too-many-elements` respectively.

Also, starting in MongoDB 5.0.4 (and 4.4.10), :query:`$mod`
returns an error if the ``divisor`` or ``remainder`` values evaluate to:

- ``NaN`` (not a number) or ``Infinity``.

- A value that cannot be represented using a 64-bit integer.

Examples
--------

Use ``$mod`` to Select Documents
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Consider a collection ``inventory`` with the following documents:
Create an ``inventory`` collection:

.. code-block:: javascript

{ "_id" : 1, "item" : "abc123", "qty" : 0 }
{ "_id" : 2, "item" : "xyz123", "qty" : 5 }
{ "_id" : 3, "item" : "ijk123", "qty" : 12 }
db.inventory.insertMany( [
{ "_id" : 1, "item" : "abc123", "qty" : 0 },
{ "_id" : 2, "item" : "xyz123", "qty" : 5 },
{ "_id" : 3, "item" : "ijk123", "qty" : 12 }
] )

Then, the following query selects those documents in the
``inventory`` collection where value of the ``qty`` field modulo
Expand All @@ -50,6 +65,7 @@ Then, the following query selects those documents in the
The query returns the following documents:

.. code-block:: javascript
:copyable: false

{ "_id" : 1, "item" : "abc123", "qty" : 0 }
{ "_id" : 3, "item" : "ijk123", "qty" : 12 }
Expand All @@ -75,11 +91,9 @@ an array that contains a single element:
The statement results in the following error:

.. code-block:: javascript
:copyable: false

error: {
"$err" : "bad query: BadValue malformed mod, not enough elements",
"code" : 16810
}
MongoServerError: malformed mod, not enough elements

Empty Array
```````````
Expand All @@ -94,11 +108,9 @@ an empty array:
The statement results in the following error:

.. code-block:: javascript
:copyable: false

error: {
"$err" : "bad query: BadValue malformed mod, not enough elements",
"code" : 16810
}
MongoServerError: malformed mod, not enough elements

.. _mod-too-many-elements:

Expand All @@ -113,10 +125,14 @@ operator with an array that contains four elements:

.. code-block:: javascript

error: {
"$err" : "bad query: BadValue malformed mod, too many elements",
"code" : 16810
}
db.inventory.find( { qty: { $mod: [ 4, 1, 2, 3 ] } } )

The statement results in the following error:

.. code-block:: javascript
:copyable: false

MongoServerError: malformed mod, too many elements

Floating Point Arguments
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions source/release-notes/5.0-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ Starting in MongoDB 5.0:
``Double()`` constructor with the :dbcommand:`replSetResizeOplog`
command.

Starting in MongoDB 5.0.4 (and 4.4.10), the :query:`$mod`
operator returns an error if the ``divisor`` or ``remainder`` values
evaluate to certain values. See :ref:`$mod behavior <mod-behavior>`.

Deprecations
~~~~~~~~~~~~

Expand Down