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

Bulk operations not including shardKey #14622

Closed
2 tasks done
matlpriceshape opened this issue May 30, 2024 · 0 comments · Fixed by #14621
Closed
2 tasks done

Bulk operations not including shardKey #14622

matlpriceshape opened this issue May 30, 2024 · 0 comments · Fixed by #14621
Milestone

Comments

@matlpriceshape
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.x.x

Node.js version

20.x.x

MongoDB server version

7.x

Typescript version (if applicable)

No response

Description

When having a sharded collection and having set shardKey on the schema, using buildBulkWriteOperations does not take the shardKey into account.

Steps to Reproduce

  1. Enable shardKey option on schema:
const measurementSchema = new Schema({
  temperature: { type: Number },
  sensorId: { type: String },
}, { shardKey: { sensorId: 1 } });

when using running

// Assuming m is an existing document
m.temperature = 21.1

await Measurement.bulkWrite([m])

This will execute a bulkWrite without the shardKey as a part of the filter condition in the updateOne command of the bulkWrite.

While this current solution will work (as ObjectIds are universally unique), including the shardKey in update will enable the to the executed on a single shard.

Expected Behavior

No response

@vkarpov15 vkarpov15 added this to the 8.4.1 milestone May 30, 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.

2 participants