When connecting to our production MongoDB servers, we want to make sure that our operations are as lightweight as possible (and are certainly non-destructive) and do not alter the database state in any sense.
The two useful utilities that we can chain to our queries are as follows:
> db.collection.find(query).maxTimeMS(999)
Our query will only take up to 999 ms, and will then return an exceeded time limit error:
> db.collection.find(query).maxScan(1000)
Our query will examine 1000 documents at the most, in order to find results and then return (no error raised).
Whenever we can, we should bind our queries by time or document result size to avoid running unexpectedly long queries that may affect our production database. A common reason for accessing our production database is troubleshooting degraded cluster performance. This can be investigated via cloud monitoring...