Caused by trying to perform an operation on an already-initialized FindCursor that requires it to be uninitialized.

If you run into this error, and you really do need to change an option on the cursor, you can rewind the cursor using FindCursor.rewind, or clone it using FindCursor.clone.

Example

await collection.find({}).toArray();

try {
  await cursor.limit(10);
} catch (e) {
  if (e instanceof CursorAlreadyInitializedError) {
  console.log(e.message); // "Cursor is already initialized..."
  }
}

Hierarchy (view full)

Constructors

Properties

message: string
name: string
stack?: string
prepareStackTrace?: ((err, stackTraces) => any)

Optional override for formatting stack traces

Type declaration

    • (err, stackTraces): any
    • Parameters

      • err: Error
      • stackTraces: CallSite[]

      Returns any

stackTraceLimit: number

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function

    Returns void