-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
On trying to save a document that fails the Mongoose validation specified in the schema, the counter for the corresponding collection still gets incremented but the document does not get saved (as expected). This results in the auto incremented ids not being continuous.
Could we add a flag that checks if the validation fails for a document and not increment the counter in that case? I had a look at the pre hook on 'validate' and this could be a potential fix:
Replace:
if ((doc.isNew && !alreadyGetId) || settings.migrate) {
with:
if ((doc.isNew && !alreadyGetId && doc.validateSync === undefined) || settings.migrate) {
I'm not sure if this is the best way to achieve this, but this could be a start.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels