Giter Club home page Giter Club logo

Comments (6)

ramiel avatar ramiel commented on May 19, 2024 1

What if the document that gets deleted is not the last one. i.e. if the last document inserted has the counter to 10 and you remove the document 5 what should happen? You cannot reset the counter to 9 or 4. This library mimic the SQL index where the index is not really bound to the entries in the DB but is more like an internal counter.

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.

from mongoose-sequence.

ramiel avatar ramiel commented on May 19, 2024 1

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.

from mongoose-sequence.

ravirajawasthi avatar ravirajawasthi commented on May 19, 2024

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.

from mongoose-sequence.

ramiel avatar ramiel commented on May 19, 2024

What is the use case? I always have the feeling that the use case may be wrong, so let me understand better yours

from mongoose-sequence.

dandv avatar dandv commented on May 19, 2024

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.

from mongoose-sequence.

vtrolinux avatar vtrolinux commented on May 19, 2024

Product.counterReset('idProduct', function(err) {
// Now the counter is 0
});

from mongoose-sequence.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.