MCPcopy Create free account
hub / github.com/Automattic/mongoose / QueryCursor

Function QueryCursor

lib/cursor/QueryCursor.js:33–54  ·  view source on GitHub ↗

* A QueryCursor is a concurrency primitive for processing query results * one document at a time. A QueryCursor fulfills the [Node.js streams3 API](https://strongloop.com/strongblog/whats-new-io-js-beta-streams3/), * in addition to several other mechanisms for loading documents from MongoDB * one

(query, options)

Source from the content-addressed store, hash-verified

31 */
32
33function QueryCursor(query, options) {
34 Readable.call(this, { objectMode: true });
35
36 this.cursor = null;
37 this.query = query;
38 this._transforms = options.transform ? [options.transform] : [];
39 var _this = this;
40 var model = query.model;
41 model.hooks.execPre('find', query, function() {
42 model.collection.find(query._conditions, options, function(err, cursor) {
43 if (_this._error) {
44 cursor.close(function() {});
45 _this.listeners('error').length > 0 && _this.emit('error', _this._error);
46 }
47 if (err) {
48 return _this.emit('error', err);
49 }
50 _this.cursor = cursor;
51 _this.emit('cursor', cursor);
52 });
53 });
54}
55
56util.inherits(QueryCursor, Readable);
57

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected