Skip to content

Commit ef79737

Browse files
committed
test(update): repro #7909
1 parent 35e9e6e commit ef79737

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/model.findOneAndUpdate.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,26 @@ describe('model: findOneAndUpdate:', function() {
12271227
});
12281228
});
12291229

1230+
it('skips setting defaults within maps (gh-7909)', function() {
1231+
const socialMediaHandleSchema = Schema({ links: [String] });
1232+
const profileSchema = Schema({
1233+
username: String,
1234+
socialMediaHandles: {
1235+
type: Map,
1236+
of: socialMediaHandleSchema,
1237+
}
1238+
});
1239+
1240+
const Profile = db.model('gh7909', profileSchema);
1241+
1242+
return co(function*() {
1243+
const update = { $setOnInsert: { username: 'test' } };
1244+
const opts = { upsert: true, setDefaultsOnInsert: true, new: true };
1245+
const doc = yield Profile.findOneAndUpdate({}, update, opts);
1246+
assert.equal(doc.socialMediaHandles, undefined);
1247+
});
1248+
});
1249+
12301250
it('runs validators if theyre set', function(done) {
12311251
const s = new Schema({
12321252
topping: {

0 commit comments

Comments
 (0)