MongoDB\Collection::estimatedDocumentCount()
New in version 1.4.
Definition
Parameters
$options
: arrayAn array specifying the desired options.
NameTypeDescriptioncommentmixedEnables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs.
This option is available since MongoDB 4.4 and will result in an exception at execution time if specified for an older server version.
New in version 1.13.
maxTimeMSintegerThe cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.
readConcernRead concern to use for the operation. Defaults to the collection's read concern.
It is not possible to specify a read concern for individual operations as part of a transaction. Instead, set the
readConcern
option when starting the transaction.readPreferenceRead preference to use for the operation. Defaults to the collection's read preference.
sessionClient session to associate with the operation.
Return Values
An estimated number of documents in the collection.
Errors/Exceptions
MongoDB\Exception\UnexpectedValueException
if the command
response from the server was malformed.
MongoDB\Exception\UnsupportedException
if options are used and
not supported by the selected server (e.g. collation
, readConcern
,
writeConcern
).
MongoDB\Exception\InvalidArgumentException
for errors related to
the parsing of parameters or options.
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
Behavior
This method returns an estimate of the count of documents in the collection
using collection metadata, rather than counting the documents or consulting an
index. This method does not take a session
option and cannot be executed
within a transaction. See
Count: Behavior
in the MongoDB manual for more information.
This method is implemented using the count
command. Due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count
command was not included in version "1" of the Stable API. Applications using
this method with the Stable API are recommended to upgrade their server version
to 5.0.9+ or disable strict mode to avoid encountering errors.
See Also
count command reference in the MongoDB manual