Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Generate Unique Sequential ID (starting from 1) with multi-user - Javascript

The application that I am building is being used by multiple users.

I am having a problem upon generating a unique ID.

My code runs like this: it will query the mongoDB for the length of all data and will add one to it so it will become unique and sequential. (For example, the database already have 40 data on it, now when the user clicked the save button, the function will get the length of the data which is 40 and it will add 1 to it. So the ID of the data will be 41.)

I encountered 2 problems. First, when the 2 user clicked the save button at the same exact time, both the data they created will have an ID of 41. Second, when the user doubled click the save button, it will still generate 2 data with both 41 as their ID.

I looked for an answer and I saw UUID but I need sequential ID that starts from 1 to infinite.

Can someone help me?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!