NodeJS and mongoose - find records from last hour NodeJS and mongoose - find records from last hour mongoose mongoose

NodeJS and mongoose - find records from last hour


From this post Popping Timestamps into ObjectIds, you need to convert the seconds from the timestamp to hexidecimal string first, something like the following:

var ObjectID = require('mongodb').ObjectID;app.get('/', function(req, res) {    var timestamp = new Date(Date.now() - 1 * 60 * 60 * 1000);    var hexSeconds = Math.floor(timestamp/1000).toString(16);    // Create an ObjectId with that hex timestamp    var constructedObjectId = ObjectID(hexSeconds + "0000000000000000");    console.log(constructedObjectId); // prints 564cd3810000000000000000    MyCollection.find({}, function(err, doc) {        MyCollection.find({            "_id": { "$gt" : constructedObjectId }        }, function (err, curr) {            res.render('index.jade', { "latest": curr, "all": doc });        });            });});