On this page本页内容
db.collection.
estimatedDocumentCount
(options)¶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驱动程序文档。
New in version 4.0.3.
Returns the count of all documents in a collection or view. 返回集合或视图中所有文档的计数。The method wraps the 该方法包装count
command.count
命令。
options | document |
The options
document can contain the following:options
文档可以包含以下内容:
maxTimeMS |
integer |
db.collection.estimatedDocumentCount()
does not take a query filter and instead uses metadata to return the count for a collection.不接受查询筛选器,而是使用元数据返回集合的计数。
On a sharded cluster, the resulting count will not correctly filter out orphaned documents.在分片集群上,结果计数将无法正确筛选出孤立文档。
After an unclean shutdown, the count may be incorrect.不干净关机后,计数可能不正确。
After an unclean shutdown of a 在使用Wired Tiger存储引擎不干净地关闭mongod
using the Wired Tiger storage engine, count statistics reported by db.collection.estimatedDocumentCount()
may be inaccurate.mongod
后,db.collection.estimatedDocumentCount()
报告的计数统计数据可能不准确。
The amount of drift depends on the number of insert, update, or delete operations performed between the last checkpoint and the unclean shutdown. 漂移量取决于在最后一个检查点和不干净关机之间执行的插入、更新或删除操作的数量。Checkpoints usually occur every 60 seconds. 检查点通常每60秒出现一次。However, 但是,使用非默认的mongod
instances running with non-default --syncdelay
settings may have more or less frequent checkpoints.--syncdelay
设置运行的mongod
实例可能有更多或更少的检查点。
Run 在validate
on each collection on the mongod
to restore the correct statistics after an unclean shutdown.mongod
上的每个集合上运行validate
,以在不干净的关闭后恢复正确的统计数据。
Starting in MongoDB 4.2, if the client that issued the 从MongoDB 4.2开始,如果发出db.collection.estimatedDocumentCount()
disconnects before the operation completes, MongoDB marks the db.collection.estimatedDocumentCount()
for termination (i.e. killOp
on the operation).db.collection.estimatedDocumentCount()
的客户端在操作完成之前断开连接,MongoDB会将db.collection.estimatedDocumentCount()
标记为终止(即,终止操作)。
The following example uses 以下示例使用db.collection.estimatedDocumentCount
to retrieve the count of all documents in the orders
collection:db.collection.estimatedDocumentCount()
检索orders
集合中所有文档的计数:
See also参阅