Skip to content

Commit

Permalink
fix(update): make upsert option consistently handle truthy values, no…
Browse files Browse the repository at this point in the history
…t just booleans, for updateOne()

Fix #5839
  • Loading branch information
vkarpov15 committed Nov 28, 2017
1 parent 5e279f4 commit 4d4dfa1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,10 @@ Query.prototype._optionsForExec = function(model) {
options.readPreference = model.schema.options.read;
}

if (options.upsert !== void 0) {
options.upsert = !!options.upsert;
}

return options;
};

Expand Down
2 changes: 1 addition & 1 deletion test/model.update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ describe('model: update:', function() {
name: String
});

var Model = db.model('gh3677', schema);
var Model = db.model('gh5839', schema);

var opts = { upsert: 1 };
Model.update({ name: 'Test' }, { name: 'Test2' }, opts, function(error) {
Expand Down

0 comments on commit 4d4dfa1

Please sign in to comment.