-
-
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
BulkSave existing documents doesn't apply save middleware hook updates #13799
Comments
I have also attempted without prefix '_' |
In the bulkSave it looks like the this.buildBulkWriteOperations needs to be called after the pre-save hooks are called otherwise the embedded document in the writeOperations (a delta for update) won't be updated. Hence why the create succeeds as it is a full document by reference and not mutated as a delta. await Promise.all(documents.map(buildPreSavePromise)); |
I'm experiencing the same issue. pre-save hooks are executed but the changes from the hooks aren't applied to the final operation when using bulkSave(). |
fix(model): make `bulkSave()` persist changes that happen in pre('save') middleware
Prerequisites
Mongoose version
7.4.5
Node.js version
18.16.0
MongoDB server version
5.7
Typescript version (if applicable)
5.1.6
Description
When the bulkSave creates documents the modifications in the "save" middleware hook at persisted.
Subsequent updates made to the documents in "save" middleware hook are not persisted.
Confirmed that the hook is being executed during the update. See console.log below
Steps to Reproduce
Output
Updating person _age to 60
Updating person _age to 61
1) it should be able to detect middleware save hook
0 passing (113ms)
1 failing
bulkSave middleware bug
it should be able to detect middleware save hook:
AssertionError: expected 60 to equal 61
-60
+61
at Context. (file:///Users/tate/code/Projects/HealthService/NodeServices/TypeScriptLibrary/src/tests/test.utils.ts:110:40)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Expected Behavior
Expect updates made in the save hook middleware to persist during a bulkSave.
The text was updated successfully, but these errors were encountered: