diff --git a/lib/model.js b/lib/model.js index 507ec49ff1d..808a595811c 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3631,7 +3631,7 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op const len = paths.length; for (let i = 0; i < len; ++i) { - where[paths[i]] = shardKey[paths[i]]; + where[paths[i]] = document[paths[i]]; } } diff --git a/test/model.test.js b/test/model.test.js index bc386146eee..b73757e4721 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -6365,9 +6365,9 @@ describe('Model', function() { describe('buildBulkWriteOperations() (gh-9673)', () => { it('builds write operations', async() => { - const userSchema = new Schema({ - name: { type: String } + name: { type: String }, + a: { type: Number } }, { shardKey: { a: 1 } }); const User = db.model('User', userSchema); @@ -6386,7 +6386,7 @@ describe('Model', function() { const desiredWriteOperations = [ { insertOne: { document: users[0] } }, { insertOne: { document: users[1] } }, - { updateOne: { filter: { _id: users[2]._id, a: 1 }, update: { $set: { name: 'I am the updated third name' } } } } + { updateOne: { filter: { _id: users[2]._id, a: 3 }, update: { $set: { name: 'I am the updated third name' } } } } ]; assert.deepEqual(