Greetings everyone! This is my first visit here, so I hope my question isn't too terrible.
I'm currently working on retrieving data from the last day, last week, and last month stored in a mongo collection.
Here's what I have attempted so far:
if(period.includes("daily")){
//search for data from 24 hours before now
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(86400, 'second').unix()}
});
}else if (period.includes("weekly")) {
//search for data from 168 hours before now (7 days)
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(604800, 'second').unix()}
});
}else if (period.includes("monthly")) {
//need help with searching for data from last month
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(xx, 'second').unix()}
});
}else{
console.error("Oops! It seems like you have entered an invalid period format. Please use 'daily, weekly, or monthly'");
}
I'm currently facing a roadblock when it comes to retrieving data from the last month as the number of days can vary. Some months have 30 days, some have 31, while February has 28 or 29 days.