Skip to content

Commit

Permalink
test(update): repro #8063
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 5, 2019
1 parent d19b849 commit f277d94
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/model.update.test.js
Expand Up @@ -3348,4 +3348,38 @@ describe('model: updateOne: ', function() {
assert.equal(docs[1].arr.length, 1);
});
});

it('update embedded discriminator path if key in $elemMatch (gh-8063)', function() {
const slideSchema = new Schema({
type: { type: String },
commonField: String
}, { discriminatorKey: 'type' });
const schema = new Schema({ slides: [slideSchema] });

const slidesSchema = schema.path('slides');
slidesSchema.discriminator('typeA', new Schema({ a: String }));
slidesSchema.discriminator('typeB', new Schema({ b: String }));

const MyModel = db.model('gh8063', schema);
return co(function*() {
const doc = yield MyModel.create({
slides: [{ type: 'typeA', a: 'oldValue1', commonField: 'oldValue2' }]
});

const filter = {
slides: { $elemMatch: { _id: doc.slides[0]._id, type: 'typeA' } }
};
const update = {
'slides.$.a': 'newValue1',
'slides.$.commonField': 'newValue2'
};
yield MyModel.updateOne(filter, update);

const updatedDoc = yield MyModel.findOne();
assert.equal(updatedDoc.slides.length, 1);
assert.equal(updatedDoc.slides[0].type, 'typeA');
assert.equal(updatedDoc.slides[0].a, 'newValue1');
assert.equal(updatedDoc.slides[0].commonField, 'newValue2');
});
});
});

0 comments on commit f277d94

Please sign in to comment.