I want to show data submissions from users only from up to one week ago at a time, rather then listing everything in the database. Is there a way to do this?
I want to show data submissions from users only from up to one week ago at a time, rather then listing everything in the database. Is there a way to do this?
Hi Cj,
Yes you can do it with filter by "_createdAt".
See example of this where clause:
pre
//Where "2014-12-30T05:01:45.973Z" is date that should be last week date.
{"_createdAt": {$gt: {"$date": "2014-12-30T05:01:45.973Z"} } }
/pre
Regards.
Ok, but what if I want it to continuously change to constantly only show the last 7. So If I check on a Tuesday it will show up to last Tuesday, Monday-Monday, exe?
Basically I'm trying to show submission history of the last 7 days.
Hi Cj,
To get it you should write custom JS code that will implement this logic.
Here is an example of code that you can change in accordance to your needs:
pre
var daysBefore = 7;
var currentTime = new Date();
var dateBefore = new Date(currentTime.getTime() - (1000 * 3600 * 24 * daysBefore ));
var whereObject = {"_createdAt": {$gt: {"$date": dateBefore.toISOString()} } };
return JSON.stringify(whereObject);
/pre
Regards.