【问题标题】:MongoDB get executionStats for aggregate queryMongoDB获取聚合查询的executionStats
【发布时间】:2017-02-16 10:38:00
【问题描述】:

我正在寻找一种方法来检索 executionStats 以进行聚合。

使用 find() 时,我可以使用 explain 轻松检索它们。 示例输出:

  "executionStats": {
    "nReturned": 332505,
    "executionTimeMillis": 1349,
    "totalKeysExamined": 332505,
    "totalDocsExamined": 332505,
    ...

但是当使用aggregations with explain enabled 时,它不会返回上面显示的统计信息。

Thisthis 是相关的,但没有给出可行的解决方案。因为这可能在此期间发生了变化,所以我打开了这个问题。

有没有什么方法可以在不测量客户端统计数据的情况下做到这一点?

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    对于 mongodb 5.0.0+,就像其他答案所说,只需使用db.collections.explain('executionStats').aggregate([])

    如果有 NO executionStats,只需更改您的 mongodb 客户端。 当我将 DataGrip 切换到 mongosh 时,出现 executionStats!

    【讨论】:

      【解决方案2】:

      在 mongodb v3.4 之前,mongo 聚合查询不支持executionStats。该问题已在 v3.6 中修复。 即db.videos.explain('executionStats').aggregate([])

      【讨论】:

        【解决方案3】:

        对我来说它是这样工作的,你已经从 3.5.5 版本中修复了这个

        它显示了执行计划和其他指标。

        db.videos.explain('executionStats').aggregate([])
        

        【讨论】:

        • The 'explain' option is illegal when a explain verbosity is also provided in mongodb 4.0.13
        【解决方案4】:

        我可以通过以下方式做到这一点:

        db.myUserCollection.explain("executionStats").aggregate([{$match: {firstName: "John"} }]);
        

        参考:https://jira.mongodb.org/browse/SERVER-19758

        【讨论】:

        • 这没有多大帮助它几乎等于explain
        【解决方案5】:

        目前(MongoDB 3.2)聚合不支持 executionStats,在聚合中使用 explain 选项可以获得一些与查询相关的数据,但其中没有 executionStats。已提议,您可以在此处查看其状态

        https://jira.mongodb.org/browse/SERVER-19758

        如果您想尽快实施,请为该问题投票。

        【讨论】:

        • 有没有绕过它,还是目前唯一的方法是在应用端测量数据?
        • 我也在搜索,如果我找到任何方法将在此处更新。
        • 您可以更新您的答案,因为聚合管道现在支持 mongodb executionStats
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-06-18
        • 1970-01-01
        • 1970-01-01
        • 2021-09-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多