- Reference >
- Database Commands >
- Diagnostic Commands >
- validate
validate¶
On this page
Definition¶
Syntax¶
The command has the following syntax:
The mongo
shell also provides a wrapper
db.collection.validate()
.
Command Fields¶
The command takes the following fields:
Field | Type | Description |
---|---|---|
validate |
string | The name of the collection to validate. |
full | boolean | Optional. A flag that determines whether the command performs a slower but more thorough check or a faster but less thorough check.
The default is Starting in MongoDB 3.6, for the WiredTiger storage engine, only the
In previous versions, the data validation process for the WT storage engine always forces a checkpoint. |
Behavior¶
The validate
command can be slow, particularly on
larger data sets.
The validate
command obtains an exclusive lock W
on
the collection. This will block all reads and writes on the collection
until the operation finishes. When run on a secondary, the
validate
operation can block all other operations on that
secondary until it finishes.
Starting in version MongoDB 4.4,
- The
$currentOp
and thecurrentOp
command includedataThroughputAverage
anddataThroughputLastSecond
information for validate operations in progress. - The log messages for validate operations include
dataThroughputAverage
anddataThroughputLastSecond
information.
Restrictions¶
MongoDB drivers automatically set afterClusterTime for operations associated with causally
consistent sessions. Starting in MongoDB 4.2, the
validate
command no longer support afterClusterTime. As such, validate
cannot be associatd
with causally consistent sessions.
Examples¶
To validate a collection
myCollection
using the default settings (i.e.full: false
)To perform a full validation of collection
myCollection
Validate Output¶
Note
The output may vary depending on the version and specific configuration of your MongoDB instance.
Specify full: true for more detailed output.
-
validate.
nInvalidDocuments
¶ The number of invalid documents in the collection.
-
validate.
nIndexes
¶ The number of indexes on the collection.
-
validate.
keysPerIndex
¶ A document that contains the name and index entry count for each index on the collection.
Starting in MongoDB 4.2 (and 4.0.10+ and 3.6.13+),
keysPerIndex
identifies the index by its name only. Earlier versions of MongoDB displayed the full namespace of the index; i.e.<db>.<collection>.$<index_name>
-
validate.
indexDetails
¶ A document that contains the status of the index validation for each index.
Starting in MongoDB 4.2 (and 4.0.10+ and 3.6.13+),
indexDetails
identifies the specific index (or indexes) that is invalid. Earlier versions of MongoDB would mark all indexes as invalid, if any of the indexes were invalid.indexDetails
identifies the index by its name only. Earlier versions of MongoDB displayed the full namespace of the index; i.e.<db>.<collection>.$<index_name>
.
-
validate.
ns
¶ The full namespace name of the collection. Namespaces include the database name and the collection name in the form
database.collection
.
-
validate.
valid
¶ A boolean that is
true
ifvalidate
determines that all aspects of the collection are valid. Whenfalse
, see theerrors
field for more information.
-
validate.
warnings
¶ An array that contains warning messages, if any, regarding the validate operation itself. The warning messages do not indicate that the collection is itself invalid. For example:
-
validate.
errors
¶ If the collection is not valid (i.e
valid
is false), this field will contain a message describing the validation error.
-
validate.
extraIndexEntries
¶ An array that contains information for each index entry that points to a document that does not exist in the collection.
Note
For the
extraIndexEntries
array, the sum of all theindexKey
field sizes has a limit of 1MB where the sizes include both the keys and values for theindexKey
. If the sum exceeds this size, the warning field displays a message.Available starting in MongoDB 4.2 (and 4.0.10+ and 3.6.13+)
-
validate.
missingIndexEntries
¶ An array that contains information for each document that is missing the corresponding index entry.
Note
For the
missingIndexEntries
array, the sum of theidKey
field size and all itsindexKey
field sizes has a limit of 1MB where the field sizes include both the keys and values for theidKey
andindexKey
. If the sum exceeds this size, the warning field displays a message.Available starting in MongoDB 4.2 (and 4.0.10+ and 3.6.13+)