【问题标题】:how to get Python Mongo Aggregate explain using db.command?如何使用 db.command 获取 Python Mongodb Aggregate 解释?
【发布时间】: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 做到这一点

标签: python mongodb pymongo


【解决方案1】:

截至 2019 年 5 月 22 日,使用 MongoDB 4.0

pymongo 目前只允许通过 db.command() 解释,这在内部使用 Aggregation Command 和 Aggregation 将解释限制为布尔开关,如 here 所示默认为 QueryPlanner

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-09
    • 2019-10-08
    • 2021-04-21
    • 2019-05-24
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多