Query to get last X minutes data with Mongodb

前端 未结 4 1636
有刺的猬
有刺的猬 2020-12-04 16:11

I\'m beginning with mongodb, and I\'m trying to query my db that have this document format:

{ \"_id\" : ObjectId(\"520b8b3f8bd94741bf006033\"), \"value\" : 0         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-04 16:23

    You could also do below

      db.getCollection('collectionName').find({timestamp : {$gte: new Date().getTime()-(60*60*1000) } } )
    

    The above query ll give you records of timestamp b/w now and 60 mins. if you like more then 60 mins - say 2 hrs you could change expression to (2*60*60*1000) for 30 mins (30*60*1000)

提交回复
热议问题