.find()
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 find hooks, but not the model's post find hooks.
Unless you're an advanced user, do not instantiate this class directly. Use Query#cursor()
instead.
Adds a cursor flag. Useful for setting the noCursorTimeout
and tailable
flags.
Marks this cursor as closed. Will stop streaming and subsequent calls to next()
will error.
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.
Registers a transform function which subsequently maps documents retrieved via the streams interface or .next()
// Map documents returned by `data` events
Thing.
find({ name: /^hello/ }).
cursor().
map(function (doc) {
doc.foo = "bar";
return doc;
})
on('data', function(doc) { console.log(doc.foo); });
// Or map documents returned by `.next()`
var cursor = Thing.find({ name: /^hello/ }).
cursor().
map(function (doc) {
doc.foo = "bar";
return doc;
});
cursor.next(function(error, doc) {
console.log(doc.foo);
});
Get the next document from this cursor. Will return null
when there are no documents left.
The options
passed in to the QueryCursor
constructor.
© 2010 LearnBoost
Licensed under the MIT License.
https://mongoosejs.com/docs/api/querycursor.html