MongoDB get executionStats for aggregate query

后端 未结 4 1782
暖寄归人
暖寄归人 2021-02-13 06:23

I am looking for a way to retrieve the executionStats for aggregations.

When using find(), I can retrieve them easily by using explain. Example output:

相关标签:
4条回答
  • 2021-02-13 07:05

    Currently(MongoDB 3.2) aggregation does not support executionStats, with explain option in aggreagation you get some data related to query but there is no executionStats in it. It is proposed and you can check its status here

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

    Please upvote the issue if you want to implement this soon.

    0 讨论(0)
  • 2021-02-13 07:17

    I was able to do it in the following way:

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

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

    0 讨论(0)
  • 2021-02-13 07:27

    executionStats was not supported for mongo aggregation queries till mongodb v3.4. The issue has been fixed in v3.6. i.e. db.videos.explain('executionStats').aggregate([])

    0 讨论(0)
  • 2021-02-13 07:29

    For me it works like this, you have this fixed in from version 3.5.5

    It shows the execution plan and other metrics.

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

    0 讨论(0)
提交回复
热议问题