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

Scoped counter with more than one reference counter fails with duplicate key #44

Closed
rernens opened this issue Feb 9, 2019 · 5 comments

Comments

@rernens
Copy link

rernens commented Feb 9, 2019

I have the requirement to keep unique sequence counter per establishment per company in an employee document.

I have specified the following using your plugin :

EmployeeSchema.plugin( AutoIncrement, { id: 'employees_counter', inc_field: 'sequence', reference_fields: ['customer', 'establishment'] } );

Inserting multiple documents with customer = '5c5498941f17864d225d18d4' and establishement = '85520050700017' works just fine a document is created in the Counters document with the following values.

{"_id":"5c5f23e0114925934b3a53b7",
   "id":"employees_counter",
   "reference_value":["\"5c5498941f17864d225d18d4\"","\"85520050700017\""],
   "seq":20
}

Resetting the counter works fine ( as per my previous issue ).

But when I want to insert a document that has a different a different establishement value for the same customer value, the insert is rejected with a duplicate key in the Counter

MongoError: E11000 duplicate key error collection: moncse.counters index: id_1_reference_value_1 dup key: { : "employees_counter", : ""5c5498941f17864d225d18d4"" }

I have read issue #34 and thought that the pb was fixed. It seems not.

This render you plug-in unusable for me if the pb is not fixed.

@ramiel
Copy link
Owner

ramiel commented Feb 9, 2019

It seems that I created the fix but never merged it. I'll look at this sonn, probably the beginning of the next week and I'll create a new major version to fix the issue

@ramiel
Copy link
Owner

ramiel commented Feb 9, 2019

I just published version 5.0.0
Can you try if it fix your problem please?

@rernens
Copy link
Author

rernens commented Feb 10, 2019

@ramiel

hi Favrizio,

Thanks for your fast reaction. I have made extensive tests importing a large quantity of documents with multiple variations of the customer and establishment reference and it worked as a charm.

Thank you very much. Great plugin.

@rernens rernens closed this as completed Feb 10, 2019
@ramiel
Copy link
Owner

ramiel commented Feb 10, 2019

Happy to hear! Btw,you never spelled my name correctly 😂

@rernens
Copy link
Author

rernens commented Feb 10, 2019

@ramiel

sorry for this Fabrizio, v and b are next to each others on my keyboard !

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

2 participants