Navigation
This is an upcoming (i.e. in progress) version of the manual.

db.collection.validate()

Description

db.collection.validate(<option>)

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 has the following syntax:

db.collection.validate( {
   full: <boolean>,         // Optional
   scandata: <boolean>      // Optional
} )

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

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

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

Field Type Description
full boolean

Optional. A flag that determines whether the command performs 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 fater but less thorough check.

The default is false.

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

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

scandata boolean

Optional. A flag that determines whether the command checks the collection data and the indexes or just the indexes.

  • If true, scans the collection data as well as the indexes.
  • If false, skips the collection data and only scans the indexes.

The default is true.

The db.collection.validate() method is a wrapper around the validate database command.

Behavior

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

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.

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

Examples

  • To validate a collection myCollection using the default settings (i.e. full: false and scandata: true )

    db.myCollection.validate()
    
  • To perform a full validation of collection myCollection

    db.myCollection.validate( { full: true } )
    
    db.myCollection.validate(true)
    
  • To scan only the indexes and skip the collection data:

    db.myCollection.validate( { scandata: false } )
    

For details of the output, see Validate Output.