それぞれのユーザーの誕生日が ISODate 日付形式であるとします。例えば。ISODate("1958-03-23T00:00:00.000Z")
. ジョンゴ集計クエリを使用して、現在の日付に誕生日を持つユーザーを取得するにはどうすればよいですか?
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());
少し早いですがお礼を。