mongoose-plugin-autoinc icon indicating copy to clipboard operation
mongoose-plugin-autoinc copied to clipboard

Auto Increment not stable, sometimes increment by 1 sometimes 2 or 3 even 4

Open eddyson1006 opened this issue 5 years ago • 1 comments

I have use this package in my project to provide autoincrement by 1 every time a new records come in. But somehow I can see that the increment is not consistence like id 10 to id 13 to id 14 to id 17 etc etc. Wondering what is the problem here?

I am using version as below: "mongoose-auto-increment": "^5.0.1", "mongoose-plugin-autoinc": "^1.1.9",

And code to use this in model as below: var mongoose = require('mongoose'), mongoosePaginate = require('mongoose-paginate'), Schema = mongoose.Schema;

var user = new Schema({ ...............long list of schema here.............. })

var mongoosePages = require('mongoose-pages');

var autoIncrement = require('mongoose-plugin-autoinc');

provider.plugin(autoIncrement.plugin, {model: 'user', field: 'unique_id', startAt: 1, incrementBy: 1});

eddyson1006 avatar Jul 20 '18 11:07 eddyson1006

I think it just happened on user saved a record with a validated failure. For example, when email is unique. User has created a new record using the same email address. . Mongodb will throw you an error and refuse to store the record, but this plugin has already counted it up.

What do you think?🤔🤔🤔 // sorry i did not seeing the date of your comment.

A-tichat avatar Apr 08 '22 06:04 A-tichat