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
feat(model): allow passing timestamps
option to Model.bulkSave(...)
#12082
Conversation
…mestamps` option re #12059
@AbdelrahmanHafez I think the issue is this line: mongoose/lib/helpers/timestamps/setupTimestamps.js Lines 42 to 45 in c48461a
setupTimestamps() registers a pre('save') hook that sets timestamps unless this.$__.saveOptions.timestamps === false .
I think that |
Thanks, @vkarpov15, that fixes it. t👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks 👍
fixes #12059
I also refactored
bulkSave
to use async/await instead of the ugly promise chain, even though I wrote it, I find it difficult to read.This comes with the downside of shorter stack traces, hopefully, this is not an issue.
@vkarpov15
There is a test failing,
bulkSave
callsbulkWrite
withtimestamps
false, so mongoose sends the writeOperations to MongoDB withoutupdatedAt
orcreatedAt
, but the documents in memory still haveupdatedAt
andcreatedAt
that is inconsistent with the database.This happens when we
document.schema.s.hooks.execPre('save',...)
. Do you know if there is a way to make pre-save hook not update timestamps? or pass an option to it? pre-post hooks seem like a blackbox to me and for years I couldn't figure out how they work.