Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda