When connecting to our production MongoDB servers, we want to make sure that our operations are as lightweight as possible (and certainly non-destructive) and do not alter the database state in any sense.
Two useful utilities 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 then return an exceeded time limit error.
> db.collection.find(query).maxScan(1000)
Our query will examine at most 1,000 documents 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 tools as described in previous...