nodkz / mongoose-plugin-autoinc

Mongoose plugin that auto-increments any ID field on your schema every time a document is saved
66 stars 15 forks source link

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

Open eddyson1006 opened 6 years ago

eddyson1006 commented 6 years ago

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});

A-tichat commented 2 years ago

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.