Skip to content

Commit

Permalink
Merge pull request #14752 from adf0nt3s/bsager/fix-incorrect-shardkey…
Browse files Browse the repository at this point in the history
…-set

Correct shardkey access in buildBulkWriteOps
  • Loading branch information
vkarpov15 authored Jul 19, 2024
2 parents 1b88765 + 693398f commit e4462c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand Down

0 comments on commit e4462c6

Please sign in to comment.