Skip to content

Commit

Permalink
Allow passing of explicit options to Model.update()
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 18, 2014
1 parent 58eafa1 commit caf76f4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,17 +534,36 @@ Model.prototype.insert = Model.prototype.create = function (object, options, cal
}, this), prepComplete);
};

Model.prototype.update = function (conditions, changes, callback) {
Model.prototype.update = function (conditions, changes, options, callback) {
/// <signature>
/// <summary>Updates all documents in the collection which match the specified conditions - making the requested changes</summary>
/// <param name="conditions" type="Object">The conditions used to select objects to be updated</param>
/// <param name="changes" type="Object">The changes to be made to objects in the collection</param>
/// <param name="callback" optional="true" value="(function(err, count) { })">A function to be called once the update has completed</param>
/// </signature>
/// <signature>
/// <summary>Updates all documents in the collection which match the specified conditions - making the requested changes</summary>
/// <param name="conditions" type="Object">The conditions used to select objects to be updated</param>
/// <param name="changes" type="Object">The changes to be made to objects in the collection</param>
/// <param name="options" type="Object">The options to be passed to the update method</param>
/// <param name="callback" value="(function(err, count) { })">A function to be called once the update has completed</param>
/// </signature>

options = options || {};

if(typeof options == 'function') {
callback = options;
options = {};
}

_.defaults(options, {
w: callback ? 1 : 0,
multi: true
});

this.toSource(conditions);

this.collection.update(conditions, changes, { w: callback ? 1 : 0, multi: true }, (function(err, modified) {
this.collection.update(conditions, changes, options, (function(err, modified) {
if (err) this.emit('error', err);
return callback(err, modified);
}).bind(this));
Expand Down

0 comments on commit caf76f4

Please sign in to comment.