I am trying to write a MongoDB query that will return data an hour ago. There is a column timewith timestamps ( "time" : NumberLong("1471953787012")), and it looks like this in SQL:
select name from table
where time between (NOW() - INTERVAL 1 HOUR) AND (NOW())
How do I write a MongoDB query to find a date range from one hour ago? I am trying with a function new Date(), but it does not work. Does anyone know what I'm doing wrong?
db.coll.find({
"time" : {
$lt: new Date(),
$gte: new Date(new Date().setDate(new Date().getDate()-1))
}
})
corry source
share