|
|
@@ -30,6 +30,10 @@ var CursorDocumentSource = module.exports = CursorDocumentSource = function Curs
|
|
|
|
|
|
klass.MaxDocumentsToReturnToClientAtOnce = 150; //DEVIATION: we are using documents instead of bytes
|
|
|
|
|
|
+klass.create = function create(ns, runner, expCtx) {
|
|
|
+ return new CursorDocumentSource(ns, runner, expCtx);
|
|
|
+};
|
|
|
+
|
|
|
proto._currentBatch = [];
|
|
|
proto._currentBatchIndex = 0;
|
|
|
|
|
|
@@ -80,7 +84,7 @@ proto.getNext = function getNext(callback) {
|
|
|
if (this.expCtx && this.expCtx.checkForInterrupt && this.expCtx.checkForInterrupt()){
|
|
|
return callback(new Error('Interrupted'));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var self = this;
|
|
|
if (self._currentBatchIndex >= self._currentBatch.length) {
|
|
|
self._currentBatchIndex = 0;
|
|
|
@@ -89,7 +93,7 @@ proto.getNext = function getNext(callback) {
|
|
|
if (err) return callback(err);
|
|
|
if (self._currentBatch.length === 0)
|
|
|
return callback(null, null);
|
|
|
-
|
|
|
+
|
|
|
return callback(null, self._currentBatch[self._currentBatchIndex++]);
|
|
|
});
|
|
|
}
|
|
|
@@ -126,10 +130,10 @@ proto.coalesce = function coalesce(nextSource) {
|
|
|
/**
|
|
|
* Record the query that was specified for the cursor this wraps, if
|
|
|
* any.
|
|
|
- *
|
|
|
+ *
|
|
|
* This should be captured after any optimizations are applied to
|
|
|
* the pipeline so that it reflects what is really used.
|
|
|
- *
|
|
|
+ *
|
|
|
* This gets used for explain output.
|
|
|
*
|
|
|
* @method setQuery
|
|
|
@@ -142,10 +146,10 @@ proto.setQuery = function setQuery(query) {
|
|
|
/**
|
|
|
* Record the sort that was specified for the cursor this wraps, if
|
|
|
* any.
|
|
|
- *
|
|
|
+ *
|
|
|
* This should be captured after any optimizations are applied to
|
|
|
* the pipeline so that it reflects what is really used.
|
|
|
- *
|
|
|
+ *
|
|
|
* This gets used for explain output.
|
|
|
*
|
|
|
* @method setSort
|
|
|
@@ -195,7 +199,7 @@ proto.serialize = function serialize(explain) {
|
|
|
|
|
|
/**
|
|
|
* returns -1 for no limit
|
|
|
- *
|
|
|
+ *
|
|
|
* @method getLimit
|
|
|
**/
|
|
|
proto.getLimit = function getLimit() {
|
|
|
@@ -204,7 +208,7 @@ proto.getLimit = function getLimit() {
|
|
|
|
|
|
/**
|
|
|
* Load a batch of documents from the Runner into the internal array
|
|
|
- *
|
|
|
+ *
|
|
|
* @method loadBatch
|
|
|
**/
|
|
|
proto.loadBatch = function loadBatch(callback) {
|
|
|
@@ -212,7 +216,7 @@ proto.loadBatch = function loadBatch(callback) {
|
|
|
this.dispose();
|
|
|
return callback;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this._runner.restoreState();
|
|
|
|
|
|
var self = this,
|