Skip to content

Commit

Permalink
test(update): repro #9468
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 7, 2020
1 parent 0335578 commit 6538e49
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5022,6 +5022,32 @@ describe('Model', function() {
});
});

it('avoids unused array filter error (gh-9468)', function() {
return co(function*() {
const MyModel = db.model('Test', new Schema({
_id: Number,
grades: [Number]
}));

yield MyModel.create([
{ _id: 1, grades: [95, 92, 90] },
{ _id: 2, grades: [98, 100, 102] },
{ _id: 3, grades: [95, 110, 100] }
]);

yield MyModel.updateMany({}, { $set: { 'grades.0': 100 } }, {
arrayFilters: [{
element: { $gte: 95 }
}]
});

const docs = yield MyModel.find().sort({ _id: 1 });
assert.deepEqual(docs[0].toObject().grades, [100, 92, 90]);
assert.deepEqual(docs[1].toObject().grades, [100, 100, 102]);
assert.deepEqual(docs[2].toObject().grades, [100, 110, 100]);
});
});

describe('watch()', function() {
before(function() {
if (!process.env.REPLICA_SET) {
Expand Down

0 comments on commit 6538e49

Please sign in to comment.