Page 1 of 1

How do I show a list of only database items from last week?

Posted: Tue Mar 03, 2015 4:13 pm
by Cj Bernauer

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?


How do I show a list of only database items from last week?

Posted: Wed Mar 04, 2015 5:53 am
by Yurii Orishchuk

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.


How do I show a list of only database items from last week?

Posted: Wed Mar 04, 2015 1:07 pm
by Cj Bernauer

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?


How do I show a list of only database items from last week?

Posted: Wed Mar 04, 2015 2:14 pm
by Cj Bernauer

Basically I'm trying to show submission history of the last 7 days.


How do I show a list of only database items from last week?

Posted: Thu Mar 05, 2015 2:28 am
by Yurii Orishchuk

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.