MongoDB\Collection::estimatedDocumentCount()
New in version 1.4.
Definition
Parameters
$options
: arrayAn array specifying the desired options.
NameTypeDescriptioncomment
mixed
Enables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs.
To use this option, you must connect to MongoDB 6.0 or later. If you are connected to an earlier version, the server returns an exception at execution time.
New in version 1.13.
maxTimeMS
integer
The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.
readConcern
Read 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.readPreference
Read preference to use for the operation. Defaults to the collection's read preference.
session
Client 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. The count
command is not included in version 1
of the
Stable API. If you enable the Stable API and want to use this
method, upgrade your server version to MongoDB 6.0 or disable strict
mode to avoid encountering errors.
See Also
count command reference in the MongoDB manual