Skip to content

Commit 51cc5a5

Browse files
committed
test(update): repro #7843
1 parent eb5078e commit 51cc5a5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/model.update.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,4 +3245,26 @@ describe('model: updateOne: ', function() {
32453245
assert.ok(doc.child.updatedAt.valueOf() >= now);
32463246
});
32473247
});
3248+
3249+
it('supports discriminators if key is specified in conditions (gh-7843)', function() {
3250+
const testSchema = new mongoose.Schema({
3251+
title: { type: String, required: true },
3252+
kind: { type: String, required: true }
3253+
}, { discriminatorKey: 'kind' });
3254+
3255+
const Test = db.model('gh7843', testSchema);
3256+
3257+
const testSchemaChild = new mongoose.Schema({
3258+
label: String
3259+
});
3260+
3261+
const TestChild = Test.discriminator('gh7843_child', testSchemaChild, 'testchild');
3262+
3263+
const filter = { label: 'bar', kind: 'testchild' };
3264+
const update = { label: 'updated' };
3265+
return Test.create({ title: 'foo', kind: 'testchild', label: 'bar' }).
3266+
then(() => Test.updateOne(filter, update)).
3267+
then(() => Test.collection.findOne()).
3268+
then(doc => assert.equal(doc.label, 'updated'));
3269+
});
32483270
});

0 commit comments

Comments
 (0)