QueryCursor

Example

Node.js 10.x supports async iterators natively without any flags. You can enable async iterators in Node.js 8.x using the .

Note: This function is not if Symbol.asyncIterator is undefined. If Symbol.asyncIterator is undefined, that means your Node.js version does not support async iterators.


Parameters
  • query «Query»
  • options «Object» query options passed to .find()
Inherits:
  • «Readable»

A QueryCursor is a concurrency primitive for processing query results one document at a time. A QueryCursor fulfills the Node.js streams3 API, in addition to several other mechanisms for loading documents from MongoDB one at a time.

QueryCursors execute the model’s pre hooks before loading any documents from MongoDB, and the model’s post find hooks after loading each document.


Parameters
  • value «Boolean»
Returns:
  • «AggregationCursor» this

Adds a cursor flag. Useful for setting the noCursorTimeout and tailable flags.


QueryCursor.prototype.close()

Parameters
  • callback «Function»
Returns:
  • «Promise»

Marks this cursor as closed. Will stop streaming and subsequent calls to will error.


Parameters
  • fn «Function»
  • [options] «Object»

  • [options.parallel] «Number» the number of promises to execute in parallel. Defaults to 1.

Returns:
  • «Promise»

Execute fn for every document in the cursor. If fn returns a promise, will wait for the promise to resolve before iterating on to the next one. Returns a promise that resolves when done.

Example


Parameters
  • fn «Function»
Returns:
  • «QueryCursor»

Registers a transform function which subsequently maps documents retrieved via the streams interface or .next()

Example


Parameters
  • callback «Function»
Returns:
  • «Promise»

Get the next document from this cursor. Will return null when there are no documents left.


function Object() { [native code] }.prototype.options

Type:

The passed in to the QueryCursor constructor.