* 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)
| 31 | */ |
| 32 | |
| 33 | function 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 | |
| 56 | util.inherits(QueryCursor, Readable); |
| 57 |
nothing calls this directly
no outgoing calls
no test coverage detected