db.collection.validate()

On this page本页内容

Description描述

db.collection.validate(<documents>)

mongo Shell Method方法

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

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 the validate command.db.collection.validate()方法是validate命令的包装器。

Syntax语法

Changed in version 4.4在版本4.4中更改

db.collection.validate() no longer accepts just a boolean parameter. db.collection.validate()不再只接受布尔参数。See db.collection.validate() Parameter Change.请参阅db.collection.validate()参数更改

The db.collection.validate() method has the following syntax:db.collection.validate()方法的语法如下所示:

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

Parameters参数

The db.collection.validate() method can take the following optional document parameter with the fields:db.collection.validate()方法可以在字段中使用以下可选文档参数:

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 with the following exception:如果为true,则执行更彻底的检查,但出现以下异常:
    • Starting in MongoDB 4.4, full validation on the oplog for WiredTiger skips the more thorough check.从MongoDB 4.4开始,WiredTiger的oplog上的完整验证跳过了更彻底的检查。
  • If false, omits some checks for a faster but less thorough check.如果为false,则省略一些检查,以便更快但不太彻底地检查。

The default is false.默认值为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.从MongoDB 3.6开始,对于WiredTiger存储引擎,在验证磁盘上的数据之前,只有完整的(full)验证过程才会强制检查点并将所有内存中的数据刷新到磁盘上。

In previous versions, the data validation process for the WT storage engine always forces a checkpoint.在以前的版本中,WT存储引擎的数据验证过程总是强制执行检查点。

Behavior行为

The db.collection.validate() method is potentially resource intensive and may impact the performance of your MongoDB instance.db.collection.validate()方法可能会占用大量资源,可能会影响MongoDB实例的性能。

The db.collection.validate() method obtains an exclusive lock on the collection. db.collection.validate()方法获取集合的独占锁。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.db.collection.validate()方法可能很慢,尤其是在较大的数据集上。

Starting in version MongoDB 4.4,从MongoDB 4.4版开始,

Examples示例

db.myCollection.validate( { full: true } )

For details of the output, see Validate Output.有关输出的详细信息,请参阅验证输出