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

205
Visualizações
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 à 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