mongodb: how can I see the execution time for the aggregate command?

前端 未结 6 1189
梦如初夏
梦如初夏 2020-12-09 02:45

I execute the follow mongodb command in mongo shell

db.coll.aggregate(...)

and i see the list of result. but is it possible to see the quer

6条回答
  •  被撕碎了的回忆
    2020-12-09 02:58

    Try .explain("executionStats"):

    db.inventory.find(
       { quantity: { $gte: 100, $lte: 200 } }
    ).explain("executionStats")
    

    Which returns a very detailed JSON with the time in "executionTimeMillis" like:

    {
       "queryPlanner" : {
             ...
       },
       "executionStats" : {
          "executionSuccess" : true,
          "nReturned" : 3,
          "executionTimeMillis" : 0,
          ...
    

    More details: https://docs.mongodb.com/manual/tutorial/analyze-query-plan/#evaluate-the-performance-of-a-query

提交回复
热议问题