• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 84
  • Last Modified:

MongoDB query based on timestamp

I have mongoDB collection and for the documents added to the collection I used timestamp field to capture the current time stamp with this format:
2016-03-19T15:49:46-05:00

I am looking for a find query to return all documents added to data base in past 24 hours.

I would appreciate your help.
0
artsec
Asked:
artsec
1 Solution
 
Evan CutlerVolunteer Chief Information OfficerCommented:
Assuming your timestamp field is called "createdAt"

db.getCollection("COLLECTION_NAME").find({"createdAt":{$gt:new Date(Date.now() - 24*60*60 * 1000)}})
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now