对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

MongoDB\Collection::estimatedDocumentCount()

1.4版本新增。

MongoDB\Collection::estimatedDocumentCount()

使用集合元数据获取集合中的估计文档数。

function countDocuments(array $options = []): integer
$options : array

指定所需选项的数组。

名称
类型
说明

comment

混合

使用户可以指定任意注释来帮助通过数据库分析器、currentOp 输出和日志来跟踪操作。

自 MongoDB 4.4 起此选项可用,如果为旧服务器版本指定,则会在执行时导致异常。

1.13版本新增。

maxTimeMS

整型

The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.

事务外的

Read concern to use for the operation. Defaults to the collection's read concern.

无法将单个操作的读关注(read concern)指定为ACID 事务的一部分。相反,请在启动ACID 事务时设立readConcern 选项。

readPreference

Read preference to use for the operation. Defaults to the collection's read preference.

会话

与操作相关联的客户端会话。

集合中文档的估计数量。

MongoDB\Exception\UnexpectedValueException ,如果来自服务器的命令响应格式错误。

MongoDB\Exception\UnsupportedException,如果所选服务器使用了选项但不支持选项(例如collation、readConcern、writeConcern)。

MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。

MongoDB\ 驱动程序\Exception\RuntimeException 用于扩展级别的其他错误(例如连接错误)。

此方法使用集合元数据返回集合中文档计数的估计值,而不是对文档进行计数或咨询索引。 此方法不带session选项,因此无法在ACID 事务中执行。 有关更多信息,请参阅MongoDB手册中的计数:行为。

This method is implemented using the count command. The count command is not included in version "1" of the Stable API. If you're using this method with the Stable API, we recommend upgrading your server version to 5.0.9+ or disabling strict mode to avoid encountering errors.