Query.prototype.maxTimeMS()

Parameters
  • [ms] «Number» The number of milliseconds
Returns:
  • «Query» this

Sets the maxTimeMS option. This will tell the MongoDB server to abort if the query or write op has been running for more than ms milliseconds.

Calling query.maxTimeMS(v) is equivalent to query.setOption({ maxTimeMS: v })

Example:

  1. const query = new Query();
  2. // Throws an error 'operation exceeded time limit' as long as there's
  3. // >= 1 doc in the queried collection
  4. const res = await query.find({ $where: 'sleep(1000) || true' }).maxTimeMS(100);