-
Notifications
You must be signed in to change notification settings - Fork 10
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
[ENHANCEMENT] working with updateOne() #91
Comments
Good question! I've thought it over, and I think I can definitely add this once a few design decisions have been made. There would be two elements to getting this working:
Grabbing the version key from the filter parameter in the pre-update hook is straightforward, as is adding a To avoid any unexpected behaviour and stick to the principle of least astonishment, the best way to implement this might be to pass a flag to the
Having the version key for OCC explicitly passed in the Let me know what you think of the above! |
Thanks for the feedback :) I agree, an explicit flag in the Another point: Is this also applicable to timestamps? E.g. depending on the plugin used on a given schema (version key or timestamp) the value of the |
Thanks! Yes, I'd think that the timestamp plugin would work in much the same way as the version key plugin; the only difference would be that Mongoose automatically updates the |
Great! I don't have time to submit a PR right now, but if you want help with this feature around mid-January I'll gladly help. |
Any update on this? |
Is there a viable way to adopt a similar strategy with
Model.updateOne()
?Pondering on how the pre-save hook works, I understand any document that is retrieved from the database (that can subsequently be
save()
d) is guaranteed to have a version key which can be used in the$where
clause of the current query. AnupdateOne()
operation might not have a versionKey suitable for this purpose.I believe a
pre('updateOne')
hook could have the same functionality aspre('save')
if the query passed has a key that matches the schema versionKey. Is this too naïve, or am I missing some obvious difficulty?Otherwise, is there an interest in adding this functionality to this package, or does it fall out of scope?
The text was updated successfully, but these errors were encountered: