mongoose-sequence icon indicating copy to clipboard operation
mongoose-sequence copied to clipboard

Customize next value

Open biluochun opened this issue 3 years ago • 1 comments

SomeSchema.plugin(AutoIncrement, {
    id: '_id',

    // default:  counter__hooks: (next) => ++next
    counter__hooks: (next: number) => {
        if (next > 100) return next + 3;
        if (next === 1024) return 1026;
        return next + 4;
    },
});

biluochun avatar Jun 20 '22 03:06 biluochun

Hi biluochun if i want to auto increment based on one of the value how to achieve ? like say i have a field with value as Inactive then in that case i should not update the sequence any idea?

Thank you

aravind-virtualTE avatar May 19 '23 12:05 aravind-virtualTE