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

throwOnValidationError for bulkWrite() and insertMany() #13256

Closed
2 tasks done
vkarpov15 opened this issue Apr 6, 2023 · 0 comments
Closed
2 tasks done

throwOnValidationError for bulkWrite() and insertMany() #13256

vkarpov15 opened this issue Apr 6, 2023 · 0 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Prerequisites

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

🚀 Feature Proposal

See #13218 (comment)

await Model.bulkWrite(ops, { throwOnValidationError: true });

await Model.insertMany(ops, { throwOnValidationError: true });

Will opt in to throwing an error if one of the ops failed validation, but all valid ops completed successfully

Motivation

Currently, insertMany() and bulkWrite() don't throw an error if there were validation errors, but all valid ops succeeded. This is a bit messy and inconsistent

Example

See proposal

@vkarpov15 vkarpov15 added new feature This change adds new functionality, like a new method or class enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Apr 6, 2023
@vkarpov15 vkarpov15 modified the milestones: 7.1.0, 7.2.0 Apr 6, 2023
vkarpov15 added a commit to lpizzinidev/mongoose that referenced this issue May 17, 2023
vkarpov15 added a commit that referenced this issue May 17, 2023
…g MongooseBulkWriteError if all valid operations succeed in `bulkWrite()` and `insertMany()`

Fix #13256
vkarpov15 added a commit that referenced this issue May 19, 2023
feat(model): add throwOnValidationError option for opting into getting MongooseBulkWriteError if all valid operations succeed in `bulkWrite()` and `insertMany()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant