Spring Data MongoDB Date Between

Do not include the ‘and(“startDate”)‘ part in your criteria.

Instead of :

query.addCriteria(Criteria.where("startDate").gte(startDate).and("startDate").lt(endDate));

You should use:

query.addCriteria(Criteria.where("startDate").gte(startDate).lt(endDate));

When you include the ‘and(“startDate”)’ part, Mongo see’s it as two different entries on the same property.

Leave a Comment