Skip to content

Commit

Permalink
test: repro #10485
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 28, 2021
1 parent 0afa2ba commit 926533f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/model.findOneAndUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2507,4 +2507,30 @@ describe('model: findOneAndUpdate:', function() {
assert.equal(doc.a, 2);
});
});

it('supports overwriting nested map paths (gh-10485)', function() {
const child = new mongoose.Schema({
vals: {
type: mongoose.Schema.Types.Map,
of: String
}
});

const parent = new mongoose.Schema({
children: {
type: [child]
}
});
const Parent = db.model('Parent', parent);

return co(function*() {
const parent = yield Parent.create({
children: [{ vals: { github: 'hello', twitter: 'world' } }]
});

const res = yield Parent.findOneAndUpdate({ _id: parent._id, 'children.vals.github': { $exists: true } },
{ $set: { 'children.$.vals': { telegram: 'hello' } } }, { new: true });
assert.deepEqual(res.toObject().children[0].vals, new Map([['telegram', 'hello']]));
});
});
});

0 comments on commit 926533f

Please sign in to comment.