【发布时间】:2019-05-22 11:35:58
【问题描述】:
从 MongoDB 3.2 开始,explain() 使用默认的详细模式 解释命令 allPlansExecution。使用不同的详细程度 使用 command() 直接运行解释命令。
我的聚合查询看起来像这样
collection.aggregate(pipeline=QUERY, explain=True)
这将返回 queryPlanner 详细而不是 executionStats。
mongo shell 支持什么?
db.Item_Process_For_Report.explain("executionStats").aggregate([])
我想做什么?
db.command('explain', <What goes here>)
【问题讨论】:
-
如果您只需要获得解释输出:
db.command('aggregate', 'things', pipeline=pipeline, explain=True)如图所示here -
这给了我
QueryPlanner而不是executionStats -
pymongo 只允许通过
db.command进行解释,这在内部使用 Aggregation Command 和聚合这种方式只允许默认为QueryPlanner的布尔规范,如 here 所示 -
没错。但是这个
db.Item_Process_For_Report.explain("executionStats").aggregate([])给了我在mongo shell 中运行时的执行统计信息。太糟糕了,我们不能用 pymongo 做到这一点