mongodb-autoincrement icon indicating copy to clipboard operation
mongodb-autoincrement copied to clipboard

fix: corner case error when counters _id is duplicated

Open futurist opened this issue 7 years ago • 0 comments

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.

futurist avatar Jan 23 '17 02:01 futurist