Closed
Description
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
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels