参考 > 参考 > mongo Shell方法 > 收集方法 > db.collection.explain()
db.collection.
explain
()¶mongo
壳法
此页面记录了mongo
shell方法,并且
没有引用MongoDB Node.js驱动程序(或任何其他驱动程序)方法。对于相应的MongoDB驱动程序API,请改为参考您特定的
MongoDB驱动程序文档。
返回有关以下方法的查询计划的信息:
从MongoDB 3.0开始 | 从MongoDB 3.2开始 |
---|---|
若要使用db.collection.explain()
,请将上述方法之一附加到db.collection.explain()
:
例如,
有关更多示例,请参见示例。另请参见 db.collection.explain()。help()。
该db.collection.explain()
方法具有以下参数:
参数 | 类型 | 描述 |
---|---|---|
verbosity |
串 | 可选的。指定说明输出的详细模式。该模式影响行为
与早期版本的向后兼容性
有关这些模式的更多信息,请参见 详细模式。 |
的行为db.collection.explain()
和返回的信息量取决于verbosity
模式。
默认情况下,db.collection.explain()
以queryPlanner
详细模式运行
。
MongoDB运行查询优化器来为评估中的操作选择胜出计划。db.collection.explain()
返回queryPlanner
评估方法的信息。
MongoDB运行查询优化器以选择获胜计划,执行获胜计划直至完成,并返回描述获胜计划执行情况的统计信息。
对于写操作,db.collection.explain()
返回有关更新或删除操作的信息会被执行,但并
没有修改应用到数据库。
db.collection.explain()
返回所评估方法的queryPlanner
和
executionStats
信息。但是,executionStats
不提供被拒绝计划的查询执行信息。
MongoDB运行查询优化器以选择中奖计划并执行中奖计划以完成。在"allPlansExecution"
模式下,MongoDB返回描述获胜计划执行情况的统计信息以及在计划选择期间捕获的其他候选计划的统计信息。
对于写操作,db.collection.explain()
返回有关更新或删除操作的信息会被执行,但并
没有修改应用到数据库。
db.collection.explain()
返回所评估方法的queryPlanner
和
executionStats
信息。其中executionStats
包括中奖计划的
完整查询执行信息。
如果查询优化器考虑了多个计划,则
executionStats
信息还包括
在计划选择阶段为获胜和被拒绝的候选计划捕获的部分执行信息。
对于写操作,db.collection.explain()
返回有关将要执行但实际上并未修改数据库的写操作的信息。
在MongoDB中4.2开始,你不能运行explain
命令/ db.collection.explain()
在executionStats
模式或allPlansExecution
一个模式包含阶段。相反,您可以:aggregation pipeline
$out
explain()
力学¶该db.collection.explain()
方法包装
explain
命令,是首选的运行方式
explain
。
db.collection.explain().find()
db.collection.find().explain()
与以下主要区别相似
:
db.collection.explain().find()
构造允许查询修饰符的其他链接。有关查询修饰符的列表,请参见db.collection.explain()。find()。help()。db.collection.explain().find()
返回游标,这需要一个电话.next()
,或它的别名.finish()
,返回explain()
结果。如果在mongo
外壳中以交互方式运行,则
mongo
外壳会自动调用.finish()
以返回结果。但是,对于脚本,必须显式调用
.next()
或.finish()
,以返回结果。有关与游标相关的方法的列表,请参见
db.collection.explain()。find()。help()。db.collection.explain().aggregate()
等效于将说明选项传递给该db.collection.aggregate()
方法。
help()
¶要查看所支持的操作列表
db.collection.explain()
,请运行:
db.collection.explain().find()
返回一个游标,它允许链接查询修饰符。要查看受支持的查询修饰符db.collection.explain().find()
以及与光标相关的方法的列表,请运行:
您可以将多个修饰符链接到db.collection.explain().find()
。有关示例,请参见解释带有修饰符的find()。
queryPlanner
模式¶默认情况下,db.collection.explain()
以"queryPlanner"
详细模式运行
。
以下示例db.collection.explain()
以"queryPlanner"
详细模式运行,
以返回指定count()
操作的查询计划信息:
executionStats
模式¶以下示例db.collection.explain()
以"executionStats"
详细模式运行,
以返回指定find()
操作的查询计划和执行信息:
allPlansExecution
模式¶以下示例db.collection.explain()
在
"allPlansExecution"
详细模式下运行。对于指定的操作,将
db.collection.explain()
返回
queryPlanner
和executionStats
对于所有考虑的计划
update()
:
注意
执行explain 不会修改数据,而是运行更新操作的查询谓词。对于候选计划,MongoDB返回在计划选择阶段捕获的执行信息 。
db.collection.explain()
操作可以返回有关以下内容的信息:
冗长模式(即queryPlanner
,executionStats
,
allPlansExecution
)确定结果是否包括
executionStats和是否executionStats包括期间捕获的数据计划选择。
有关输出的详细信息,请参见解释结果。