title: MongoDB get executionStats for aggregate query
body: <p>I am looking for a way to retrieve the <code>executionStats</code> for aggregations.</p>
  
  <p>When using find(), I can retrieve them easily by using <a href="https://docs.mongodb.com/manual/reference/explain-results/" rel="noreferrer">explain</a>.
  Example output:</p>
  
  <pre><code>  "executionStats": {
      "nReturned": 332505,
      "executionTimeMillis": 1349,
      "totalKeysExamined": 332505,
      "totalDocsExamined": 332505,
      ...
  </code></pre>
  
  <p>But when using <a href="https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/#return-information-on-aggregation-pipeline-operation" rel="noreferrer">aggregations with explain enabled </a>it won't return the stats shown above.</p>
  
  <p><a href="https://jira.mongodb.org/browse/DOCS-6306" rel="noreferrer">This</a> and <a href="https://stackoverflow.com/questions/31970636/mongodb-aggregation-is-there-a-way-to-get-executionstats-from-an-aggregate-curs">this</a> is related but there is no viable solution given. Because this might have changed in the meantime, I opened this question. </p>
  
  <p>Is there any way this can be done without measuring the stats on the client side? </p>