-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
"update" and "findByIdAndUpdate" don't increment "__v" #6994
Comments
Thanks for reporting, will investigate ASAP |
I took a closer look at this and this is going to have to wait for a minor release. Right now update operations never update the version key, we'll have to add a |
Hi vkarpov15, thank you for preparing this feature :-) |
I dug into this for 5.4 and I think its best to implement this as a plugin for now. Check out mongoose-update-versioning on npm and our docs |
is this being looked at still? |
@DigivolveIo please check the mongoose-update-versioning plugin docs |
I guess by design, someone thought the update functions do not need to increment __v.
For me it seems like a bug, as I expected it always to be updated.
There has already been an issue about it, but was not resolved: #1265
The Issue is in all mongoose Versions (tested with mongoose 5, 4, 3).
Problem
Someone with an older version of the doc could overwrite a newer version.
Example: Two people editing a document in the frontend - and they both want to save it. We might get version conflicts, but as __v is not updated, we cannot check it.
Conclusion
Code Snippet for Testing and Workaround
I made a script for testing - copy it in a file 'mongoose__v.js' and execute it with:
The script will create a document 'catty' in the collection 'kitten' on the first run. Execute it several times to try to update the version. The console.logs will show, that __v is not updated.
workaround
Uncomment those lines and execute the script again several times - now __v should be updated.
Also this works, it would be really great, if it would be the mongoose default.
The text was updated successfully, but these errors were encountered: