Java/MongoDB query by date

后端 未结 6 1414
南旧
南旧 2020-12-01 10:04

I stored a value as a java.util.Date() in my collection, but when I query to get values between two specific dates, I end up getting values outside of the range. Here\'s my

6条回答
  •  悲哀的现实
    2020-12-01 10:47

    I approach the query like this

    new Document("datetime",Document.parse(
        "{$gte: ISODate('" + new SimpleDateFormat("yyyy-MM-dd").format(fromDate) + "'), 
         $lte: ISODate('" + new SimpleDateFormat("yyyy-MM-dd").format(endDate) + "')}"
    ))
    

提交回复
热议问题