- Reference >
- MongoDB\Collection Class >
- MongoDB\Collection::explain()
MongoDB\Collection::explain()
New in version 1.4.
Definition
-
MongoDB\Collection::explain
Explain the given command.
This method has the following parameters:
Parameter Type Description $explainable
MongoDB\Operation\Explainable
The command to explain. $options
array Optional. An array specifying the desired options. The
$options
parameter supports the following options:Option Type Description comment
mixed Optional. Enables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs.
Defaults to the
comment
of the explained operation (if any).This is not supported for server versions prior to 4.4 and will result in an exception at execution time if used.
New in version 1.13.
readPreference
MongoDB\Driver\ReadPreference Optional. Read preference to use for the operation. Defaults to the collection’s read preference. typeMap
array Optional. The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the collection’s type map.
This will be used for the returned command result document.
verbosity
string Optional. The verbosity level at which to run the command. See the explain command for more information.
Return Values
An array or object with the result document of the explain command. The return type will depend on the
typeMap
option.
Errors/Exceptions
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 driver level (e.g. connection errors).
Explainable Commands
Explainable commands include, but are not limited to:
MongoDB\Operation\Aggregate
MongoDB\Operation\Count
MongoDB\Operation\DeleteMany
MongoDB\Operation\DeleteOne
MongoDB\Operation\Distinct
MongoDB\Operation\Find
MongoDB\Operation\FindOne
MongoDB\Operation\FindOneAndDelete
MongoDB\Operation\FindOneAndReplace
MongoDB\Operation\FindOneAndUpdate
MongoDB\Operation\UpdateMany
MongoDB\Operation\UpdateOne
Examples
This example explains a count command.
The output would then resemble:
See Also
- explain command reference in the MongoDB manual