-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Unordered bulkWrite()
with validation errors doesn't execute the bulk write
#13176
Comments
Remove the const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
num: Number
});
const User = mongoose.model('User', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
await User.bulkWrite([{ updateOne: { filter: {}, update: { num: 'not a number'}, upsert: true }},
{
updateOne: { filter: {}, update: { num: 42 } }
}], {ordered: false}).then(() => null, err => err);
console.log(await User.find())
console.log('done');
}
run(); |
fix(model): execute valid write operations if calling `bulkWrite()` with ordered: false
Unfortunately, this fix broke the A potential solution would be to move the empty |
Prerequisites
Mongoose version
6.x
Node.js version
Doesn't matter
MongoDB server version
Doesn't matter
Typescript version (if applicable)
No response
Description
General idea is the following code throws a validation error and doesn't execute the one valid bulk write op, even though
ordered: false
is setReported in Slack: https://mongoosejsteam.slack.com/archives/C2CA1AWQP/p1678894562556919
"Hey I’m trying to use writeBulk with multiple updateOne unordered. When one entity throws error (For example doesn’t pass scheme validation) all the bulk get reverts, and I get a general error of cast fails. I would like to update the entities that able to be updated, and get error that contains the entities failed to update, similar to the the insertMany behavior. Does anyone have an idea?"
Steps to Reproduce
See above
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: