mongodb-autoincrement
mongodb-autoincrement copied to clipboard
fix: corner case error when counters _id is duplicated
The duplicate may from arguments passed from user:
autoIncrement.getNextSequence(db, 'test', 'ID', function(e, ID) {})
... ...
autoIncrement.getNextSequence(db, 'test', 'ID2', function(e, ID) {})
Before this PR, ID2
will never show any errors, but the program hang, because the error message is:
{
name: 'MongoError',
message: 'E11000 duplicate key error index: test3.counters.$_id_ dup key: { : "test" }',
ok: 0,
errmsg: 'E11000 duplicate key error index: test3.counters.$_id_ dup key: { : "test" }',
code: 11000
}
See, the error code is also 11000
, but should throw in this case.