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
How do you ensure that the ShortId used in Mongoose won't be duplicated? Or if duplication happens then? #65
Comments
Yes, mongoose will give you the error There is https://github.com/jjwchoy/mongoose-shortid but this actually uses an internal shortid generation system. If there aren't yet modules, you could look at the source code of this one and build your own module! |
@manuel-di-iorio thanks! i just implemented something by using the
Note: |
👍 Module wrapper:
Use it with:
PS: I would also place the |
@manuel-di-iorio thanks a lot! |
Just some notes for anyone reading this in the future. In the Kaijun code, I believe |
As we see in the doc
I consider if
shortid.generate
will accidentally generate a duplicated id for the record.If it really happens, will mongoose throw an error something like
duplicated index error
by saving the new record, or will it regenerate a new id automatically until it's not duplicated anymore?The text was updated successfully, but these errors were encountered: