My goal is to retrieve data from MongoDB that is exactly a week old.
The specific field I am focusing on is -
{
_id:821398723913,
closed_at:"2020-06-10T01:43:59-04:00"
}
I am looking to fetch all objects where the 'closed_at' field falls within a week's time frame. Despite searching online, none of the suggested solutions seem to be effective.
Edit:
Here are some attempts I have made so far -
db.Orders.aggregate([{
$project: {
date: {
$dateFromString: {
dateString: '$date'
}
}
}
}, {
$match: {
"closed_at": {
$lt: lastDayWeek,
$gt: firstDayWeek
}
}
}]);
and
Orders.find({'closed_at': {
$gte: new Date((new Date().getTime() - (15 * 24 * 60 * 60 * 1000)))
}, 'cancelled_at': null}).sort({_id: 1});
I require the data to be fetched from Monday to Monday and I have been attempting to use $isoWeek without success so far