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

204
Vistas
Mongodb: how to pass current date filter in aggregate pipeline from javascript

I'm trying to get a simple date-filtered aggregation working.

I have documents like:

{ 
  "name" : "Article 1",
  "expires" : <some date [type:datetime]> 
},
{ 
  "name" : "Article 1",
  "expires" : <some other date [type:datetime]>
},
...

I'm trying to query them with an aggregate pipeline over a call from javascript, so my pipeline is passing over as JSON.

I want to get all unexpired documents, but I haven't found a way to use the $$NOW variable that works for me.

var pipeline = [
 {'$sort' : {[name] : 1}},
 { "$match": {
    "expires": {"$gt": "$$NOW"}
   }
 }
];

await myGetData(collection, pipeline).then(resp => ...

I've also tried variations of $dateFromString without any success. This should be simple, so I assume I'm doing something dumb.

The issue seems to be getting the correct date format into the pipeline JSON. From other stackoverflow questions, it seems that it needs to be a data object for comparison? Not sure how to describe that in the JSON though.

Could someone please point me in the right direction? Thanks

about 4 years ago · Juan Pablo Isaza
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