1

Please help, I need to filter between dates using java mongodb driver below is is my Filtering operation however, its failed to select between the date

FindIterable<Document> documents = collection
                .find(Filters.and("started", gte("2019-01-01T00:00:00.000Z"),   lt("2019-03-01T00:00:00.000Z")))

Therefore, I want to be about to filter for Date range.

Afeez Olawale
  • 65
  • 4
  • 13

1 Answers1

-1

You are doing your filter operation on String representation of dates. You can try the following in order for Spring-data to construct your filter with $date operator.

Instant from = Instant.parse("2019-01-01T00:00:00.000Z");
Instant to = Instant.parse("2019-03-01T00:00:00.000Z");

FindIterable<Document> documents = collection.find(Filters.and("started", gte(from),lt(to)));
charlycou
  • 1,778
  • 13
  • 37