Skip to content

Commit

Permalink
fix(aggregate): add chainable .option() helper for setting arbitrary …
Browse files Browse the repository at this point in the history
…options

Fix #5829
  • Loading branch information
vkarpov15 committed Nov 17, 2017
1 parent 22d4657 commit bb840f5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,31 @@ Aggregate.prototype.explain = function(callback) {
*/

Aggregate.prototype.allowDiskUse = function(value) {
if (!this.options) {
this.options = {};
}
this.options.allowDiskUse = value;
return this;
};

/**
* Lets you set arbitrary options, for middleware or plugins.
*
* ####Example:
*
* var agg = Model.aggregate(..).option({ allowDiskUse: true }); // Set the `allowDiskUse` option
* agg.options; // `{ allowDiskUse: true }`
*
* @param {Object} value keys to merge into current options
* @see mongodb http://docs.mongodb.org/manual/reference/command/aggregate/
* @return {Aggregate} this
* @api public
*/

Aggregate.prototype.option = function(value) {
for (var key in Object.keys(value)) {
this.options[key] = value[key];
}
return this;
};

/**
* Sets the cursor option option for the aggregation query (ignored for < 2.6.0).
* Note the different syntax below: .exec() returns a cursor object, and no callback
Expand Down

0 comments on commit bb840f5

Please sign in to comment.