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

前端 未结 6 1185
梦如初夏
梦如初夏 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 03:13

    I will write an answer to explain this better.

    Basically there is no explain() functionality for the aggregation framework yet: https://jira.mongodb.org/browse/SERVER-4504

    However there is a way to measure client side but not without its downsides:

    • You are not measuring the database
    • You are measuring the application
    • There are too many unknowns about the in between parts to be able to get an accurate reading, i.e. you can't say that it took 0.04ms for the document result to be formulated by the MongoDB server, serialised, sent over the wire, de-serialised by the app and then stored into a hash allowing you subtract that sum from the total to get a aggregation benchmark.

    However that being said, you might be able to get a slightly accurate result by doing it in MongoDB console on the same server as the mongos / mongod. This will create very little in betweens, still too many but enough to maybe get a reading you could roughly trust. As such you could use @Zagorulkin's answer in that position.

提交回复
热议问题