Query mongo on timestamp

Viewed 21577

I want to query Mongo based on timestamp. Follwing is the field in mongo.

"timestamp" : "2016-03-07 11:33:48"

Books is the collection name and below is my query for time period of 1 minute:

db.Books.find({"timestamp":{$gte: ISODate("2016-03-07T11:33:48.000Z"), $lt: ISODate("2016-03-07T11:34:48.000Z")}})

Also is there any alternative like I don't have to give greater and lower limit on timestamp. But query based time interval mentioned. Something like, if present timestamp is TS = "2016-03-07T11:33:48.000Z" then query should be between TS and TS + 1 minute rather than explicitly mentioning timestamp. Something like adding 1 minute to present timestamp

1 Answers
Related