Cj Bernauer
Posts: 0
Joined: Wed Oct 22, 2014 5:47 pm

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

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?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

Cj Bernauer
Posts: 0
Joined: Wed Oct 22, 2014 5:47 pm

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

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?

Cj Bernauer
Posts: 0
Joined: Wed Oct 22, 2014 5:47 pm

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

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

Return to “Issues”