1

I need to filter my data from mongo db collection by date. I created following query for complete this task:

new Criteria(Constants.MONGO_POST_CREATION_DATE).gte(DateUtil.getUTCDate(searchDTO.getStartDate())

this criteria generates following query:

{ "creationTime" : { "$gte" : { "$date" : "2018-10-28T21:00:00.000Z"} , "$lte" : { "$date" : "2019-02-06T08:29:00.000Z"}}}

But i couldn't get any data by using this query. It just returns empty result list. I've found following question on stackoverflow which explains how to write correct query for filtering by Date:
Question

So, with query from that answer i'm able to get expected result from mongo:

{ "creationTime" : { "$gte" : new Date("2019-01-24T21:00:00.000Z") , "$lte" : new Date("2019-02-06T08:29:00.000Z")}}

What do i need to change to force Criteria generate proper query for Date?

iChrome
  • 443
  • 1
  • 6
  • 24

0 Answers0