Type Alias RunCursorCommandOptions

RunCursorCommandOptions: {
    awaitData?: boolean;
    readPreference?: ReadPreferenceLike;
    session?: ClientSession;
    tailable?: boolean;
    timeoutMode?: CursorTimeoutMode;
    timeoutMS?: number;
} & BSONSerializeOptions

Type declaration

  • OptionalawaitData?: boolean
  • OptionalreadPreference?: ReadPreferenceLike
  • Optionalsession?: ClientSession
  • Optionaltailable?: boolean
  • Optional ExperimentaltimeoutMode?: CursorTimeoutMode

    Specifies how timeoutMS is applied to the cursor. Can be either 'cursorLifeTime' or 'iteration' When set to 'iteration', the deadline specified by timeoutMS applies to each call of cursor.next(). When set to 'cursorLifetime', the deadline applies to the life of the entire cursor.

    Depending on the type of cursor being used, this option has different default values. For non-tailable cursors, this value defaults to 'cursorLifetime' For tailable cursors, this value defaults to 'iteration' since tailable cursors, by definition can have an arbitrarily long lifetime.

    const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
    for await (const doc of cursor) {
    // process doc
    // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
    // will continue to iterate successfully otherwise, regardless of the number of batches.
    }
    const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
    const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
  • Optional ExperimentaltimeoutMS?: number

    Specifies the time an operation will run until it throws a timeout error. Note that if maxTimeMS is provided in the command in addition to setting timeoutMS in the options, then the original value of maxTimeMS will be overwritten.