Set time limit for a MongoDB query
The maxTimeMS
option can be used on a cursor to limit the maximum time that the query is allowed to run. If the query is interrupted when serving batches, the client will get the ready batches.
It’s handy for pathological cases in text search, which may cause resource exhaustion.