1.4版本新增。
定义
参数
$options: array指定所需选项的数组。
名称类型说明comment
混合
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.
会话
与操作相关联的客户端会话。
Return Values
集合中文档的估计数量。
错误/异常
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.
另请参阅
MongoDB 手册中的count命令参考