Reputation: 465
I am using mongoDB for storing data .I have create a user schema .
The idea is ,apart from the mongodb automatic generate _id ,I will still need another automatic generate publish_id for showing to users(between:10-12) . The question is: how can I make it ?
Thank you so much for your help !!
Upvotes: 0
Views: 105
Reputation: 106
You can use nanoid. You have to install it with npm i nanoid
. It will create you a random unique id.
In your controller when you are creating a new user, requires nanoid and then just use it. You can pass as parameter the length you want the id have. For exmaple: nanoid(48)
Upvotes: 1