I am trying to get the Mongo database to return all of the records created within the past week.
Each record has a field 'created at' which will be something like '6/22/17 09:14'. How do I check if this date occurred in the past week?
I have some code that looks like this:
the_collection.find({ALERT_CREATED : {> : new Date() - ONE_WEEK}}).toArray(function(error, results) {
if (error) {
callback(error);
} else {
callback(null, results);
}
});
With the different date formats, the two dates can't be compared.
UPDATE:
To clarify the issue, the dates in the database have the form 6/22/17 09:14 and as such cannot be compared correctly against a Date() object. Is there any way to compare them correctly?