db.collection.validate()
On this page
Description
db.collection.validate(<documents>)
Important
mongo Shell Method
This page documents a
mongo
method. This is not the documentation for database commands or language-specific drivers, such as Node.js. To use the database command, see thevalidate
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
Validates a collection. The method scans a collection data and indexes for correctness and returns the result. For details of the output, see Validate Output.
The
db.collection.validate()
method is a wrapper around thevalidate
command.
Syntax
Note
Changed in version 4.4
db.collection.validate()
no longer accepts just a boolean
parameter. See db.collection.validate() Parameter Change.
The db.collection.validate()
method has the following syntax:
db.collection.validate( { full: <boolean> // Optional } )
Parameters
The db.collection.validate()
method can take the
following optional document parameter with the fields:
Field | Type | Description |
---|---|---|
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
Performance
The db.collection.validate()
method is potentially resource
intensive and may impact the performance of your MongoDB instance,
particularly on larger data sets.
The db.collection.validate()
method obtains an exclusive lock
on the collection. This will block all reads and writes on the
collection until the operation finishes. When run on a secondary, the
operation can block all other operations on that secondary until it
finishes.
Warning
Validation has exclusive lock requirements that affect performance.
Consider only running db.collection.validate()
on nodes
that are not servicing reads and writes.
To isolate the impact of the validation operation from client
applications, run db.collection.validate()
on a secondary
node.
Convert a secondary node into a replica set
hidden member and use the hidden
node to further isolate the db.collection.validate()
operation.
Tip
Convert the current primary node to a secondary node with
rs.stepDown()
.
Data Throughput Metrics
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.
Examples
To validate a collection
myCollection
using the default settings (i.e.{ full: false
)db.myCollection.validate() db.myCollection.validate({ }) db.myCollection.validate( { full: false } ) To perform a full validation of collection
myCollection
, specify full: true.db.myCollection.validate( { full: true } )
For details of the output, see Validate Output.