Skip to content

Commit

Permalink
test(document): repro #9319
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 27, 2020
1 parent 54ed471 commit c78c42d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/document.test.js
Expand Up @@ -9286,4 +9286,29 @@ describe('document', function() {
const doc = new Test({ publisher: 'Mastering JS' });
assert.deepEqual(doc.toObject().authors, ['Mastering JS']);
});

it('handles pulling array subdocs when _id is an alias (gh-9319)', function() {
const childSchema = Schema({
field: {
type: String,
alias: '_id'
}
}, { _id: false });

const parentSchema = Schema({ children: [childSchema] });
const Parent = db.model('Parent', parentSchema);

return co(function*() {
yield Parent.create({ children: [{ field: '1' }] });
const p = yield Parent.findOne();

p.children.pull('1');
yield p.save();

assert.equal(p.children.length, 0);

const fromDb = yield Parent.findOne();
assert.equal(fromDb.children.length, 0);
});
});
});

0 comments on commit c78c42d

Please sign in to comment.