Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulkWrite operations on any sharded collection are completely broken in 8.4.1+ #14753

Closed
2 tasks done
adf0nt3s opened this issue Jul 18, 2024 · 0 comments · Fixed by #14752
Closed
2 tasks done

bulkWrite operations on any sharded collection are completely broken in 8.4.1+ #14753

adf0nt3s opened this issue Jul 18, 2024 · 0 comments · Fixed by #14752

Comments

@adf0nt3s
Copy link
Contributor

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.3.4

Node.js version

18.20.4

MongoDB server version

6.x

Typescript version (if applicable)

5.4.5

Description

buildBulkWriteOperations adds the shard key to the filter condition, but it sets it to the schema's value, not the document's value. The test that covers this bit of logic passed because it wasn't really using an updated shard key value

Steps to Reproduce

I've opened a PR here. The test i adjusted will fail with the current logic

For convenience, i've pasted the test below

    it('builds write operations', async() => {

      const userSchema = new Schema({
        name: { type: String },
        a: { type: Number }
      }, { shardKey: { a: 1 } });

      const User = db.model('User', userSchema);

      const users = [
        new User({ name: 'Hafez1_gh-9673-1', a: 1 }),
        new User({ name: 'Hafez2_gh-9673-1', a: 2 }),
        new User({ name: 'I am the third name', a: 3 })
      ];

      await users[2].save();
      users[2].name = 'I am the updated third name';

      const writeOperations = User.buildBulkWriteOperations(users);

      const desiredWriteOperations = [
        { insertOne: { document: users[0] } },
        { insertOne: { document: users[1] } },
        { updateOne: { filter: { _id: users[2]._id, a: 3 }, update: { $set: { name: 'I am the updated third name' } } } }
      ];

      assert.deepEqual(
        writeOperations,
        desiredWriteOperations
      );

    });

Expected Behavior

No response

@adf0nt3s adf0nt3s changed the title buildBulkWriteOperations incorrectly sets the shard key value on the where filter bulkWrite operations on any sharded collection are completely broken in 8.4.1+ Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant