Skip to content

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

Closed
@rernens

Description

@rernens

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions