Cursor Methods: Max Time Milliseconds

Defining a maximum time for executing an operation in the query.

🪶 The maxTimeMs method defines a maximum time in milliseconds for executing a query operation.

For example cursor.maxTimeMS(2000) limits the query to 2000 milliseconds (or 2 seconds).

1
  • import
  • MerlinDB,
  • {
  • Schema
  • }
  • from
  • "@chrisaxxwell/merlin-db";
    2
  • //Or if you are using 'merlindb.max.js' just call 'new MerlinDB()';
  • 3
    4
  • const
  • merlin =
  • new
  • MerlinDB(
  • )
  • ;
    5merlin
  • .connect(
  • "USER-DATABASE"
  • )
  • ;  
    6
  • var
  • userModel = merlin
  • .model(
  • "User", <userSchema>
  • )
  • ;
    7
    8
  • //cursor.maxTimeMS(<number>);
  • 9userModel
  • .find(
  • {
  • name:
  • {
  • $eq:
  • "Charles"
  • }
  • }
  • )
  • 10
  • .maxTimeMS(
  • 2000
  • )
  • 11
  • .catch(
  • e =>
  • {
  • 12   console
  • .log(
  • e
  • )
  • ;
    13  
  • //returns: Error: operation exceeded time 2000ms!
  • 14
  • }
  • )