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

Since Updating to mongoose 5.0.2 #7

Open
alexpchin opened this issue Jan 29, 2018 · 6 comments
Open

Since Updating to mongoose 5.0.2 #7

alexpchin opened this issue Jan 29, 2018 · 6 comments

Comments

@alexpchin
Copy link
Contributor

Since updating, my test with async parallel:

it('should assign pids for parallel async parallel requests', done => {
    async.parallel(
      [
        function(cb) {
          User.create(
            {
              email: `testing+tenant${Math.floor(
                Math.random() * 1000000000000
              )}@pad.co.uk`,
              password: 'password',
              passwordConfirmation: 'password',
              firstName: 'Tenant',
              lastName: `Person ${Math.floor(Math.random() * 10000)}`,
              image: 'http://fillmurray.com/300/300',
              mobile: '+447441393986', // Alex hushed number
              role: 'tenant'
            },
            (err, docs) => {
              if (err) {
                throw cb(err);
              }
              cb(null, docs);
            }
          );
        },
        function(cb) {
          User.create(
            {
              email: `testing+tenant${Math.floor(
                Math.random() * 1000000000000
              )}@pad.co.uk`,
              password: 'password',
              passwordConfirmation: 'password',
              firstName: 'Tenant',
              lastName: `Person ${Math.floor(Math.random() * 10000)}`,
              image: 'http://fillmurray.com/300/300',
              mobile: '+447441393986', // Alex hushed number
              role: 'tenant'
            },
            (err, docs) => {
              if (err) {
                throw cb(err);
              }
              cb(null, docs);
            }
          );
        },
        function(cb) {
          User.create(
            {
              email: `testing+tenant${Math.floor(
                Math.random() * 1000000000000
              )}@pad.co.uk`,
              password: 'password',
              passwordConfirmation: 'password',
              firstName: 'Tenant',
              lastName: `Person ${Math.floor(Math.random() * 10000)}`,
              image: 'http://fillmurray.com/300/300',
              mobile: '+447441393986', // Alex hushed number
              role: 'tenant'
            },
            (err, docs) => {
              if (err) {
                throw cb(err);
              }
              cb(null, docs);
            }
          );
        }
      ],
      function(err, results) {
        if (err) {
          throw (err);
        }
        const pids1 = results.map(user => user.pid);
        const pids2 = [0, 1, 2];
        (JSON.stringify(pids1.sort()) === JSON.stringify(pids2.sort())).should
          .be.true;
        done();
      }
    );
  });

Throws an error:

Uncaught E11000 duplicate key error collection: pad-test.identitycounters index: field_1_groupingField_1_model_1 dup key: { : "pid", : "", : "User" }

@sp3c1 And I are looking into it at the moment... It looks like something to do with compound indexes? You said you tested with mongoose 5? However, the dependencies are not 5 - (I don't think). What version did you test with?

Any ideas?

@alexpchin
Copy link
Contributor Author

alexpchin commented Jan 29, 2018

Use of plugin in user schema:

UserSchema.plugin(autoIncrement, { model: 'User', field: 'pid' });

@alexpchin
Copy link
Contributor Author

The identitycounters collection is only storing the last value -> i.e:

{ 
    "_id" : ObjectId("5a6f7851b50b3c0c5bec7879"), 
    "groupingField" : "", 
    "count" : NumberInt(2), 
    "model" : "User", 
    "field" : "pid", 
    "__v" : NumberInt(0)
}

Is stored.

@alexpchin
Copy link
Contributor Author

alexpchin commented Jan 29, 2018

Works with mongoose@4.13.10.
Fails with mongoose@5.0.0.

@nodkz
Copy link
Owner

nodkz commented Feb 6, 2018

@alexpchin was made better error catch on duplicate ids for Mongoose 5.0. It may solve this problem, please check the latest version from npm.

Also you may open PR with new tests cases, which will demonstrate broken behavior https://github.com/nodkz/mongoose-plugin-autoinc/blob/master/src/__tests__/parallel-test.js

Thanks.

@sp3c1
Copy link
Contributor

sp3c1 commented Feb 26, 2018

still get some errors on Mongoose 5+. Will try to debug that today.

@sp3c1
Copy link
Contributor

sp3c1 commented Feb 26, 2018

Okay, synopsis is

in 5+ the Mongoos/Mongo error cames as name: 'BulkWriteError'. I think we might just drop to check the status code, as everything else might be really changing

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

No branches or pull requests

3 participants