Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB get executionStats for aggregate query

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:

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

But when using aggregations with explain enabled it won't return the stats shown above.

This and this is related but there is no viable solution given. Because this might have changed in the meantime, I opened this question.

Is there any way this can be done without measuring the stats on the client side?

like image 300
j9dy Avatar asked Oct 07 '16 12:10

j9dy


4 Answers

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.

like image 74
Puneet Singh Avatar answered Sep 22 '22 09:09

Puneet Singh


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

like image 40
Max Avatar answered Sep 21 '22 09:09

Max


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([])

enter image description here

like image 34
Adnan Boota Avatar answered Sep 19 '22 09:09

Adnan Boota


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([])

like image 27
Prasenjit Saha Avatar answered Sep 19 '22 09:09

Prasenjit Saha