It's the first time I come here so I hope my question won't be too bad.
I'm trying to pick the data from last day, last week and last month that are stored in a mongo collection.
So actually I did:
if(period.includes("daily")){
//search for 24h before now
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(86400, 'second').unix()}
});
}else if (period.includes("weekly")) {
//search for 168h before now (7days)
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(604800, 'second').unix()}
});
}else if (period.includes("monthly")) {
//search for last month
DockerStatsToKeep.find({
read: { "$gte": moment(new Date()).subtract(xx, 'second').unix()}
});
}else{
console.error("this is not a valid period format, please use 'daily, weekly or monthly'");
}
But I'm stuck for the last month and I can't find a way to do it. Because month are sometimes 30days or 31days or 29days