Skip to content

Commit

Permalink
fix; proper support for .update(doc) (Fix #3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 9, 2015
1 parent b5329a1 commit 73de49c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -1989,20 +1989,27 @@ Query.prototype._execUpdate = function(castedQuery, castedDoc, options, callback

Query.prototype.update = function(conditions, doc, options, callback) {
if ('function' === typeof options) {
// Scenario: update(conditions, doc, callback)
// .update(conditions, doc, callback)
callback = options;
options = null;
} else if ('function' === typeof doc) {
// Scenario: update(doc, callback);
// .update(doc, callback);
callback = doc;
doc = conditions;
conditions = {};
options = null;
} else if ('function' === typeof conditions) {
// .update(callback)
callback = conditions;
conditions = undefined;
doc = undefined;
options = undefined;
} else if (typeof conditions === 'object' && !doc && !options && !callback) {
// .update(doc)
doc = conditions;
conditions = undefined;
options = undefined;
callback = undefined;
}

// make sure we don't send in the whole Document to merge()
Expand Down

0 comments on commit 73de49c

Please sign in to comment.