Skip to content

DOCS-14821 Adding metadata flag context to validate() #6068

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

Closed
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
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
} )

: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
8 changes: 8 additions & 0 deletions source/release-notes/5.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,14 @@ The :dbcommand:`validate` command and :method:`db.collection.validate()`
helper method also return a new :data:`~validate.repaired` boolean value
that is ``true`` if the collection was repaired.

Metadata Option Added for ``validate`` Command
Copy link
Collaborator

@jeff-allen-mongo jeff-allen-mongo Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on #6067, we probably shouldn't mention this on the 5.0 release notes since it's not applicable to all minor releases of 5.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, reopened a PR : #6069

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Starting in MongoDB 5.0, the :dbcommand:`validate` command and
the :method:`db.collection.validate()` helper method have a new
:ref:`metadata <cmd-validate-metadata>` option that quickly validates
collections and detects invalid index options.

``validate`` Command Reports Document Schema Violations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down