Skip to content

Commit e4462c6

Browse files
authored
Merge pull request #14752 from adf0nt3s/bsager/fix-incorrect-shardkey-set
Correct shardkey access in buildBulkWriteOps
2 parents 1b88765 + 693398f commit e4462c6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: lib/model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3631,7 +3631,7 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op
36313631
const len = paths.length;
36323632

36333633
for (let i = 0; i < len; ++i) {
3634-
where[paths[i]] = shardKey[paths[i]];
3634+
where[paths[i]] = document[paths[i]];
36353635
}
36363636
}
36373637

Diff for: test/model.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6365,9 +6365,9 @@ describe('Model', function() {
63656365
describe('buildBulkWriteOperations() (gh-9673)', () => {
63666366
it('builds write operations', async() => {
63676367

6368-
63696368
const userSchema = new Schema({
6370-
name: { type: String }
6369+
name: { type: String },
6370+
a: { type: Number }
63716371
}, { shardKey: { a: 1 } });
63726372

63736373
const User = db.model('User', userSchema);
@@ -6386,7 +6386,7 @@ describe('Model', function() {
63866386
const desiredWriteOperations = [
63876387
{ insertOne: { document: users[0] } },
63886388
{ insertOne: { document: users[1] } },
6389-
{ updateOne: { filter: { _id: users[2]._id, a: 1 }, update: { $set: { name: 'I am the updated third name' } } } }
6389+
{ updateOne: { filter: { _id: users[2]._id, a: 3 }, update: { $set: { name: 'I am the updated third name' } } } }
63906390
];
63916391

63926392
assert.deepEqual(

0 commit comments

Comments
 (0)