MongoDB: Only fetch documents created in the last 24hrs?

后端 未结 7 1988
遇见更好的自我
遇见更好的自我 2020-12-03 04:41

I want to limit a query I\'m making to only look in documents that were created in the past 24 hrs.

What is the best way to structure this query? How do I go about

相关标签:
7条回答
  • 2020-12-03 05:29

    For anyone else landing here via google, you can do this in the mongo shell as follows:

    db.collection.find({ $where: function () { return Date.now() - this._id.getTimestamp() < (24 * 60 * 60 * 1000)  }  })
    
    0 讨论(0)
提交回复
热议问题