1.4版本新增。
定义
参数
$explainable:MongoDB\Operation\Explainable- 要解释的命令。
$options: array指定所需选项的数组。
名称类型说明comment
混合
readPreference
Read preference to use for the operation. Defaults to the collection's read preference.
typeMap
阵列
应用游标的类型映射,决定如何将BSON文档转换为PHP值。默认为集合的类型映射。
这将用于返回的命令结果文档。
详细程度
字符串
运行命令的详细程度。 有关详细信息,请参阅解释命令。
Return Values
An array or object with the result document of the explain command. The return type will depend on the typeMap option.
错误/异常
MongoDB\Exception\UnsupportedException,如果所选服务器使用了选项但不支持选项(例如collation、readConcern、writeConcern)。
MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。
MongoDB\ 驱动程序\Exception\RuntimeException 用于扩展级别的其他错误(例如连接错误)。
可解释的命令
可解释的命令包括但不限于:
MongoDB\Operation\AggregateMongoDB\Operation\CountMongoDB\Operation\DeleteManyMongoDB\Operation\DeleteOneMongoDB\Operation\DistinctMongoDB\Operation\FindMongoDB\Operation\FindOneMongoDB\Operation\FindOneAndDeleteMongoDB\Operation\FindOneAndReplaceMongoDB\Operation\FindOneAndUpdateMongoDB\Operation\UpdateManyMongoDB\Operation\UpdateOne
示例
此示例解释了计数命令。
$collection = (new MongoDB\Client)->test->restaurants; $count = new MongoDB\Operation\Count( $collection->getDatabaseName(), $collection->getCollectionName(), ['cuisine' => 'Italian'] ); $result = $collection->explain($count); var_dump($result);
而输出将类似如下所示:
object(MongoDB\Model\BSONDocument)#29 (1) { ["storage":"ArrayObject":private]=> array(4) { ["queryPlanner"]=> object(MongoDB\Model\BSONDocument)#21 (1) { ["storage":"ArrayObject":private]=> array(6) { ["plannerVersion"]=> int(1) ["namespace"]=> string(16) "test.restaurants" ["indexFilterSet"]=> bool(false) ["parsedQuery"]=> object(MongoDB\Model\BSONDocument)#15 (1) { ["storage":"ArrayObject":private]=> array(1) { ["cuisine"]=> object(MongoDB\Model\BSONDocument)#14 (1) { ["storage":"ArrayObject":private]=> array(1) { ["$eq"]=> string(7) "Italian" } } } } ["winningPlan"]=> object(MongoDB\Model\BSONDocument)#19 (1) { ["storage":"ArrayObject":private]=> array(2) { ["stage"]=> string(5) "COUNT" ["inputStage"]=> object(MongoDB\Model\BSONDocument)#18 (1) { ["storage":"ArrayObject":private]=> array(3) { ["stage"]=> string(8) "COLLSCAN" ["filter"]=> object(MongoDB\Model\BSONDocument)#17 (1) { ["storage":"ArrayObject":private]=> array(1) { ["cuisine"]=> object(MongoDB\Model\BSONDocument)#16 (1) { ["storage":"ArrayObject":private]=> array(1) { ["$eq"]=> string(7) "Italian" } } } } ["direction"]=> string(7) "forward" } } } } ["rejectedPlans"]=> object(MongoDB\Model\BSONArray)#20 (1) { ["storage":"ArrayObject":private]=> array(0) { } } } } ["executionStats"]=> object(MongoDB\Model\BSONDocument)#27 (1) { ["storage":"ArrayObject":private]=> array(7) { ["executionSuccess"]=> bool(true) ["nReturned"]=> int(0) ["executionTimeMillis"]=> int(24) ["totalKeysExamined"]=> int(0) ["totalDocsExamined"]=> int(25359) ["executionStages"]=> object(MongoDB\Model\BSONDocument)#25 (1) { ["storage":"ArrayObject":private]=> array(14) { ["stage"]=> string(5) "COUNT" ["nReturned"]=> int(0) ["executionTimeMillisEstimate"]=> int(20) ["works"]=> int(25361) ["advanced"]=> int(0) ["needTime"]=> int(25360) ["needYield"]=> int(0) ["saveState"]=> int(198) ["restoreState"]=> int(198) ["isEOF"]=> int(1) ["invalidates"]=> int(0) ["nCounted"]=> int(1069) ["nSkipped"]=> int(0) ["inputStage"]=> object(MongoDB\Model\BSONDocument)#24 (1) { ["storage":"ArrayObject":private]=> array(14) { ["stage"]=> string(8) "COLLSCAN" ["filter"]=> object(MongoDB\Model\BSONDocument)#23 (1) { ["storage":"ArrayObject":private]=> array(1) { ["cuisine"]=> object(MongoDB\Model\BSONDocument)#22 (1) { ["storage":"ArrayObject":private]=> array(1) { ["$eq"]=> string(7) "Italian" } } } } ["nReturned"]=> int(1069) ["executionTimeMillisEstimate"]=> int(20) ["works"]=> int(25361) ["advanced"]=> int(1069) ["needTime"]=> int(24291) ["needYield"]=> int(0) ["saveState"]=> int(198) ["restoreState"]=> int(198) ["isEOF"]=> int(1) ["invalidates"]=> int(0) ["direction"]=> string(7) "forward" ["docsExamined"]=> int(25359) } } } } ["allPlansExecution"]=> object(MongoDB\Model\BSONArray)#26 (1) { ["storage":"ArrayObject":private]=> array(0) { } } } } ["serverInfo"]=> object(MongoDB\Model\BSONDocument)#28 (1) { ["storage":"ArrayObject":private]=> array(4) { ["host"]=> string(9) "localhost" ["port"]=> int(27017) ["version"]=> string(5) "3.6.1" ["gitVersion"]=> string(40) "025d4f4fe61efd1fb6f0005be20cb45a004093d1" } } ["ok"]=> float(1) } }
另请参阅
- MongoDB 手册中的解释命令参考