Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 80
  • 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 CutlerCommented:
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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