Say that I've got a collection of users, each with a birthday in ISODate date format. eg. ISODate("1958-03-23T00:00:00.000Z")
. How can I use a jongo aggregate query to get users with birthdays on the current day.This is what I have currently but it doesn't return any results even though there are users with birthdays:
Date dateOfBirth = new Date();
Integer month = new DateTime(dateOfBirth).getMonthOfYear();
Integer day = new DateTime(dateOfBirth).getDayOfMonth();
List<User> users= IteratorUtils.toList(userJongo.aggregate("
{$project:_id:1,dateOfBirth:1,name:1}}")
.and("{$match :{dateOfBirth.getDate(): {$eq: '"+day+"'}}}")
.and("{$match :{dateOfBirth.getMonth()+1: {$eq:'"+month+"'}}}")
.and("{$limit:"+limit+"}"
.as(User.class).iterator());
Thank inadvance.