I have the following schema in mongodb, where the timestamp is the timestamp at an hourly level

```
{
    "day_chan1" : 54.464,
    "day_chan2" : 44.141,
    "day_chan3" : 44.89,
    "gatewayId" : "443719005AA3",
    "timestamp" : ISODate("2016-02-15T23:00:00.000Z"),
    "total_curr_chan" : 5.408,
    "total_day_chan" : 143.495,
    "type" : 1
}

```

I want to be able to query the last timestamp for the day for the last 7 days and 30 days. In order to do this, I am thinking of doing something like

```
    var d = new Date(); // today!

for(var i =1; i <= 7; i++) {

        var n = i; // go back n days!
        d.setDate(d.getDate() - n);
        d.setHours(23,0,0);

    var query =  {
        gatewayId: req.params.deviceId,
        timestamp: { $lt: new Date(d) }
    };

       db
        .find(query,function(resp) {
            //return the data here 
        });
    }

```

But this creates a problem of multiple callbacks and I want to know if there is an easier way of doing so using aggregates or some other method