Permalink
Browse files

Handle 2.6's empty $set (SERVER-12266) error as gracefully as possibl…

…e without significant API change
  • Loading branch information...
1 parent 8d253c6 commit c1efafb2b05bf3ed455ad6ce9631d69240c76498 @vkarpov15 vkarpov15 committed May 7, 2014
Showing with 6 additions and 4 deletions.
  1. +3 −1 lib/query.js
  2. +3 −3 test/model.findAndUpdateOne.test.js
View
@@ -1511,7 +1511,9 @@ Query.prototype._findAndModify = function (type, callback) {
if (!castedDoc) {
if (opts.upsert) {
// still need to do the upsert to empty doc
- castedDoc = { $set: {} };
+ var doc = utils.clone(castedQuery);
+ delete doc._id;
+ castedDoc = { $set: doc };
} else {
return this.findOne(callback);
}
@@ -425,13 +425,13 @@ describe('model: findOneAndUpdate:', function(){
assert.equal(undefined, doc._doc.ignore);
assert.equal(name, doc.name);
- S.findOneAndUpdate({ _id: s._id }, { ignore: true }, { upsert: true }, function (err, doc) {
+ S.findOneAndUpdate({ name: 'orange crush' }, { ignore: true }, { upsert: true }, function (err, doc) {
assert.ifError(err);
assert.ok(!doc.ignore);
assert.ok(!doc._doc.ignore);
- assert.equal('orange crush', doc.name, 'doc was not overwritten with {} during upsert');
+ assert.equal('orange crush', doc.name);
- S.findOneAndUpdate({ _id: s._id }, { ignore: true }, function (err, doc) {
+ S.findOneAndUpdate({ name: 'orange crush' }, { ignore: true }, function (err, doc) {
db.close();
assert.ifError(err);
assert.ok(!doc.ignore);

0 comments on commit c1efafb

Please sign in to comment.