Mongodb – Prevent duplicated user id using a locked thread in Next.js
I use MongoDB to store user data. The user id goes incrementally, such as 1, 2, 3, 4 etc when new user register. I have the following code to generate the user id. "users" is the name of the collection…