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

前端 未结 6 1190
梦如初夏
梦如初夏 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:15

    You can add a time function to your .mongorc.js file (in your home directory):

    function time(command) {
        const t1 = new Date();
        const result = command();
        const t2 = new Date();
        print("time: " + (t2 - t1) + "ms");
        return result; 
    }
    

    and then you can use it like so:

    time(() => db.coll.aggregate(...))
    

    Caution

    This method doesn't give relevant results for db.collection.find()

提交回复
热议问题