Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: corner case error when counters _id is duplicated #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

futurist
Copy link

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.

The duplicate may from arguments passed from user:

``` javascript
    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant