-
-
Notifications
You must be signed in to change notification settings - Fork 56
-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Reset to specific value or decrement method #79
Comments
What if the document that gets deleted is not the last one. i.e. if the last document inserted has the counter to I would say this is not a feature I'd implement but maybe I'm missing some use case, so let's discuss further if you think it's worth it. |
Maybe a function like resetCounter, but to change the value of counter to a specific value? I new to mongoose and your package is super useful. |
What is the use case? I always have the feeling that the use case may be wrong, so let me understand better yours |
I can imagine a use case of deleting the last batch of documents, e.g. a bunch of spam users or spam comments. But it's got to be the very last, and I'm not sure re-setting the counter is worth the risk that you'll later overwrite a legit document. There are already risks with not using the native ObjectID. |
But even in that case, you should not reset the counter or decrease. When you delete documents, the counter must be always the highest possible, not the first available. In SQL world it's how it works. If you delete last row which has an index of 5, next insertion will have index of 6, not 5. |
Product.counterReset('idProduct', function(err) { |
Sometimes a model object that I use the incrementer for gets deleted. Once that happens, I would like to decrement the counter again or to reset it to the value before.
Would this feature be possible to add? Otherwise you have to directly manipulate the collection as a workaround.
The text was updated successfully, but these errors were encountered: