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 query execution time? Is there any equivalent function for explain method for aggregation queries.
600MB/s maximum instantaneous data transfers. 7200 RPM spindle. Average latency = 4.16ms.
find. The aggregation query takes ~80ms while the find query takes 0 or 1ms.
With aggregate + $match, you get a big monolithic BSON containing all matching documents. With find, you get a cursor to all matching documents. Then you can get each document one by one.
var before = new Date() #aggregation query var after = new Date() execution_mills = after - before
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With