MongoDB comparing dates only without times

前端 未结 5 1422
南旧
南旧 2020-12-11 15:15

How do I query for a date field in MongoDB with the date only, and not times? For example, if MongoDB stores July 7, 2015 with any time, I want to match that day o

5条回答
  •  萌比男神i
    2020-12-11 15:41

    I guess You should make a range query between the start of the day and its ending(or without ending if you are talking about today). Something like this

    db.collection.find({
      "date" : {"$gte": new Date("2015-07-07T00:00:00.000Z"),
                "$lt": new Date("2015-07-08T00:00:00.000Z")}
    })
    

提交回复
热议问题