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

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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