Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
JS: ordinate access to mongoDB

i have a little problem, i thought how to resolve it but i don't know if it's the right way.

in my project I have several functions, all of which must use a sequential unique id every time a function is executed

for example:

person 1 runs function X using id 1
person 2 runs function Y using id 2
person 3 runs function Z using id 3
person 4 runs function Y using id 4
person 1 runs function Z using id 5
....

how to do that?

I thought to save that id in a table inside mongoDB and every time it will used inside a function, the function will increment it, but i don't think it is the right way, it is?

then, if it is the right way, how to co-ordinate the access to the DB? like if 2 people runs 2 functions in the same time, the will take the same ID from DB and this absolutely must not happen, every time a function is called a different id must be used, how can I do?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use findOneAndUpdate

Example:

db.collection.findOneAndUpdate(
   { "name" : "function_trigger_count" },
   { $inc: { "count: 1 } }
)

FindOneAndUpdate ensure the atomicity of the query

OR

If you are using MongoDB version 5.x you can use Transaction feature to ensure the atomicity

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda