Mongo Query to find documents that are added in last 12 hours
I have created field in MongoDB document which stores the document creation date. How can I query to get all documents that were added in the last 12 hours?
1 Answer
6 years ago by Eleven
Following MongoDB query will get documents that were added in the last 12 hours, assuming the field that sores the date is created.
db.getCollection("your-collection-name").find( { "created" : { $gt : new Date( Date.now() - 12 * 60 * 60 * 1000 ) } } );
6 years ago by Karthik Divi