Search code examples
mongodbdatemongoose

how to match documents based on the date of execution of the query in mongoose


I'm writing a pipeline for a mongoose query which requires matching dates with the current date. I could use "new Date()" to obtain the new date but the pipeline is created once at server start. How can I write a statement which evaluates to the date of execution of the query? Maybe the date can be computed by mongodb itself?


Solution

  • Try using $currentDate operator, in your pipeline.

    Documentation link.