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

278
Vistas
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 Respuestas
Responde la pregunta

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 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