Navigation

validate

On this page

Definition

validate

The validate command checks the structures within a namespace for correctness by scanning the collection’s data and indexes. The command returns information regarding the on-disk representation of the collection.

Note

validate command does not support views and raises an error when run against a view.

The validate command can be slow, particularly on larger data sets. While the validate command is running, it holds an exclusive lock on the collection. This will block all reads and writes until the validate command finishes.

validate has the following prototype form:

{ validate: <collection> }

You may also specify one of the following options:

  • full: true provides a more thorough scan of the data.
  • scandata: false skips the scan of the collection data without skipping scans of any indexes.

The mongo shell also provides a wrapper db.collection.validate():

db.collection.validate();

Examples

Use one of the following forms to validate a collection:

db.collection.validate()
db.collection.validate(true)
db.runCommand( { validate: "collection", full: true } )

Note

Due to the manner in which validate scans data structures, even a full collection validation cannot detect all forms of corruption on MMAPv1 storage engine data files.

Output

Note

The output may vary depending on the version and specific configuration of your MongoDB instance.

validate produces different output depending on which storage engine you are using. Specify { full: true } for more detailed output.

The following fields are common to the MMAPv1 and WiredTiger storage engines:

validate.ns

The full namespace name of the collection. Namespaces include the database name and the collection name in the form database.collection.

validate.nrecords

The number of documents in the collection.

validate.nIndexes

The number of indexes on the collection.

validate.keysPerIndex

A document containing a field for each index. The value for each field is the number of keys (or documents referenced) in the index.

validate.valid

A boolean that is true if validate determines that all aspects of the collection are valid. When false, see the errors field for more information.

validate.errors

If the collection is not valid (i.e valid is false), this field will contain a message describing the validation error.

validate.ok

An integer with the value 1 when the command succeeds. If the command fails the ok field has a value of 0.

The following fields are specific to MMAPv1:

validate.firstExtent

The disk location of the first extent in the collection. The value of this field also includes the namespace.

validate.lastExtent

The disk location of the last extent in the collection. The value of this field also includes the namespace.

validate.extentCount

The number of extents in the collection.

validate.extents

validate returns one instance of this document for every extent in the collection. This embedded document is only returned when you specify the full option to the command.

validate.extents.loc

The disk location for the beginning of this extent.

validate.extents.xnext

The disk location for the extent following this one. “null” if this is the end of the linked list of extents.

validate.extents.xprev

The disk location for the extent preceding this one. “null” if this is the head of the linked list of extents.

validate.extents.nsdiag

The namespace this extent belongs to (should be the same as the namespace shown at the beginning of the validate listing).

validate.extents.size

The number of bytes in this extent.

validate.extents.firstRecord

The disk location of the first record in this extent.

validate.extents.lastRecord

The disk location of the last record in this extent.

validate.datasize

The number of bytes in all data records. This value does not include deleted records, nor does it include extent headers, nor record headers, nor space in a file unallocated to any extent. datasize includes record padding.

validate.lastExtentSize

The size of the last new extent created in this collection. This value determines the size of the next extent created.

validate.padding

A floating point value between 1 and 2.

When MongoDB creates a new record it uses the padding factor to determine how much additional space to add to the record. The padding factor is automatically adjusted by mongo when it notices that update operations are triggering record moves.

validate.firstExtentDetails

The size of the first extent created in this collection. This data is similar to the data provided by the extents embedded document; however, the data reflects only the first extent in the collection and is always returned.

validate.firstExtentDetails.loc

The disk location for the beginning of this extent.

validate.firstExtentDetails.xnext

The disk location for the extent following this one. “null” if this is the end of the linked list of extents, which should only be the case if there is only one extent.

validate.firstExtentDetails.xprev

The disk location for the extent preceding this one. This should always be “null.”

validate.firstExtentDetails.nsdiag

The namespace this extent belongs to (should be the same as the namespace shown at the beginning of the validate listing).

validate.firstExtentDetails.size

The number of bytes in this extent.

validate.firstExtentDetails.firstRecord

The disk location of the first record in this extent.

validate.firstExtentDetails.lastRecord

The disk location of the last record in this extent.

validate.objectsFound

The number of records actually encountered in a scan of the collection. This field should have the same value as the nrecords field.

validate.invalidObjects

The number of records containing BSON documents that do not pass a validation check.

Note

This field is only included in the validation output when you specify the full option.

validate.bytesWithHeaders

This is similar to datasize, except that bytesWithHeaders includes the record headers. In version 2.0, record headers are 16 bytes per document.

Note

This field is only included in the validation output when you specify the full option.

validate.bytesWithoutHeaders

bytesWithoutHeaders returns data collected from a scan of all records. The value should be the same as datasize.

Note

This field is only included in the validation output when you specify the full option.

validate.deletedCount

The number of deleted or “free” records in the collection.

validate.deletedSize

The size of all deleted or “free” records in the collection.

←   top whatsmyuri  →