Search code examples
javascriptnode.jsmongodbmongoosemern

trying to query a database based on date range would doesn't this work?


something.aggregate().match({
     createdAt: { $gte: '2020-03-02', $lte: '2021-03-02' },
   });

(also tried wrapping the dates in ISODate an Date) returns an empty list

example db entry

{
    "_id": ,
    "createdAt": "2020-09-10T18:56:15.094Z",
    "updatedAt": "2020-09-10T18:56:15.094Z",
}

Solution

  • needed to do

    new Date('2020-03-02')