Skip to content

Commit

Permalink
fix(aggregate): remove support for inline results for aggregate (#1620)
Browse files Browse the repository at this point in the history
Per DRIVERS-350, All aggregation commands must either include
the 'cursor' option or 'explain':true.

Fixes NODE-1224
  • Loading branch information
daprahamian committed Dec 19, 2017
1 parent 35d2d3e commit 84457ec
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions lib/collection.js
Expand Up @@ -2494,10 +2494,8 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
throw toError('cursor options must be an object');
}

if (this.s.topology.capabilities().hasAggregationCursor) {
options.cursor = options.cursor || { batchSize: 1000 };
command.cursor = options.cursor;
}
options.cursor = options.cursor || { batchSize: 1000 };
command.cursor = options.cursor;

// promiseLibrary
options.promiseLibrary = this.s.promiseLibrary;
Expand All @@ -2517,28 +2515,7 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
return this.s.topology.cursor(this.s.namespace, command, options);
}

if (options.cursor) {
return handleCallback(
callback,
null,
this.s.topology.cursor(this.s.namespace, command, options)
);
}

// For legacy server versions, we execute the command and format the result
this.s.db.command(command, options, function(err, result) {
if (err) {
handleCallback(callback, err);
} else if (result['err'] || result['errmsg']) {
handleCallback(callback, toError(result));
} else if (typeof result === 'object' && result['serverPipeline']) {
handleCallback(callback, null, result['serverPipeline']);
} else if (typeof result === 'object' && result['stages']) {
handleCallback(callback, null, result['stages']);
} else {
handleCallback(callback, null, result.result);
}
});
return handleCallback(callback, null, this.s.topology.cursor(this.s.namespace, command, options));
};

define.classMethod('aggregate', { callback: true, promise: false });
Expand Down

0 comments on commit 84457ec

Please sign in to comment.