Skip to content

Commit

Permalink
test(query): repro #4911
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 22, 2017
1 parent 6f16c6b commit 7cd0a79
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/model.update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,30 @@ describe('model: update:', function() {
});
});

it('avoids nested paths if setting parent path (gh-4911)', function(done) {
var EmbeddedSchema = mongoose.Schema({
embeddedField: String
});

var ParentSchema = mongoose.Schema({
embedded: EmbeddedSchema
});

var Parent = db.model('gh4911', ParentSchema);

var newDoc = {
_id: new mongoose.Types.ObjectId(),
embedded: null
};

var opts = { upsert: true, setDefaultsOnInsert: true };

Parent.
findOneAndUpdate({ _id: newDoc._id }, newDoc, opts).
then(function() { done(); }).
catch(done);
});

it('doesnt set default on upsert if query sets it', function(done) {
var s = new Schema({topping: {type: String, default: 'bacon'}, base: String});
var Breakfast = db.model('gh-860-1', s);
Expand Down

0 comments on commit 7cd0a79

Please sign in to comment.