Saturday, 6 May 2017

Query MongoDb records from 5 days ago using '_id'

I've read online that '_id' holds a timestamp on when it was created and you are able to query it depending on a date. This is what I've I tried so far, but not having any luck.

var d = new Date();
d.setDate(d.getDate() - 5);

collection.find( { }, { metal: 1, change: 1, percent: 1, _id: { $gte: d } } ).toArray(function(err, results) {
    console.log(results);
});



via user992731

No comments:

Post a Comment