How to Measure Total Execution Time of MongoDB Queries

Tadashi Shigeoka ·  Sat, December 14, 2019

I’ll introduce how to measure the total execution time of MongoDB queries.

MongoDB | モンゴディービー

Background: Want to Measure Query Execution Time Other Than explain()

To measure execution time of MongoDB find or aggregate queries, there are the following methods:

This article introduces how to measure total execution time of JavaScript code spanning multiple lines, not just measuring a single find() or aggregate().

Sample Code for Measuring Total Execution Time of MongoDB Queries

var before = new Date()

// execute your query

load('/path/to/your_query.js')

var after = new Date()
var executionMilliseconds = after - before

print(executionMilliseconds + ' ms')
print(executionMilliseconds/1000 + ' sec')

That’s all from the Gemba.

Reference Information