mongodb: how can I see the execution time for the aggregate command?
var before = new Date()
#aggregation query
var after = new Date()
execution_mills = after - before
Or you can install the excellent mongo-hacker, which automatically times every query, pretty()
fies it, colorizes the output, sorts the keys, and more:
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()
i see that in mongodb there is a possibility to use this two command:
db.setProfilingLevel(2)
and so after the query you can use db.system.profile.find() to see the query execution time and other