diff --git a/lib/aggregate.js b/lib/aggregate.js index 022fa7a6f3a..40cb9273ceb 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -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