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

116
Vistas
Is mongoose findOne guaranteed to return the latest inserted doc it finds?

I have the following in the database:

username: Murat1010
firstName: Murat
lastName: Paşa
city: İstanbul
createdAt: 2022-07-15T23:24:32.382+00:00

username: Ömer98
firstName: Ömer
lastName: Demir
city: İstanbul
createdAt: 2022-07-15T23:25:00.023+00:00


username: Yaser334
firstName: Yasser
lastName: Tayyar
city: İstanbul
createdAt: 2022-07-15T23:27:59.688+00:00

I have the following Mongoose code:

const newestMember = await Users.findOne({city: "İstanbul"})

Is newestMember guaranteed to return Murat's Doc? guaranteed to return the newest one? can I stick to findOne? If it's not correct, then how?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

No it's not guaranteed. Read here I would do:

const newestMember = await Users.findOne({city: "İstanbul"}).sort({createdAt: -1})
about 4 years ago · Santiago Gelvez 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