Filtering Dates in MongoDB

Posted by

When filtering dates from submitted data in MongoDB the date field requires little bit of MongoRecordsWithDatesrocket science. In my Mongo collection I store a field called formsubmissionDate with an ISO date value.

 

To filter on specific date values you need to create a new date within your filter. In JavaScript you’d code something along the lines of “var myisodate = new Date().toISOString()”. A MongoDB filter is  somewhat the same. You’d create a filter with an embedded declaration of a new ISODate to retrieve the dates you were looking to find.

{ formsubmissionDate: { $gte: new ISODate(“2019-02-01T20:15:31Z”) } }