Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!