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

275
Visualizações
MongoDB - Find single dates before and after today

I'm trying to write a query to find 2 individual documents dated before and after today, I need the values returned as a cursor as this is a Meteor publication (Perhaps not relevant).

I am currently using this

const today = new Date(); 
const before = db.lesson.findOne({lsn_id:kjsflf, lsn_dt:{$lte:today}}, {limit:1});
const after = db.lesson.findOne({lsn_id:kjsflf, lsn_dt:{$gte:today}}, {limit:1});

Ideally the result would be something like this:

return db.lesson.find({BEST QUERY EVER});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you are trying to combine these two queries you can try using MongoDB's $or:

    db.lesson.find({
     lsn_id: kjsflf,
     $or: [
       { lsn_dt: { $lte: today }},
       { lsn_dt: { $gte: today }}
     ]}, { limit: 2 });

This works well if there only exists one and only one document before "today" and one and only one document after "today". If there are other documents it will retrieve the first two documents it finds.

https://docs.mongodb.com/manual/reference/operator/query/or/

over 4 years ago · Santiago Trujillo 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