db.collection.validate()

Description

  • db.collection.validate()

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

Validates a collection. The method scans a collection data andindexes for correctness and returns the result. For details of theoutput, see Validate Output.

The db.collection.validate() method has the following syntax:

  1. db.collection.validate( {
  2. full: <boolean> // Optional
  3. } )

To specify only the full option, you can also use:

  1. db.collection.validate( <boolean> ) // full option

The db.collection.validate() method can take thefollowing optional document parameter with the fields:

FieldTypeDescriptionfullbooleanOptional. A flag that determines whether the commandperforms a slower but more thorough check or a faster but less thorough check.

  • If true, performs a more thorough check.
  • If false, omits some checks for a faster but lessthorough check.The default is false.

Starting in MongoDB 3.6, for the WiredTiger storage engine, only thefull validation process will force a checkpoint and flush allin-memory data to disk before verifying the on-disk data.

In previous versions, the data validation process for the WT storage enginealways forces a checkpoint.

The db.collection.validate() method is a wrapperaround the validatedatabasecommand.

Behavior

The db.collection.validate() method is potentially resourceintensive and may impact the performance of your MongoDB instance.

The db.collection.validate() method obtains an exclusive lockon the collection. This will block all reads and writes on thecollection until the operation finishes. When run on a secondary, theoperation can block all other operations on that secondary until itfinishes.

The db.collection.validate() method can be slow, particularlyon larger data sets.

Examples

  • To validate a collection myCollection using the default settings(i.e. full: false )
  1. db.myCollection.validate()
  • To perform a full validation of collection myCollection
  1. db.myCollection.validate( { full: true } )
  2.  
  3. db.myCollection.validate(true)

For details of the output, see Validate Output.