Du kan bruge aggregeringsrammen med $dayOfYear
operatør. Jeg har antaget, at fødselsdagen er gemt i feltet birthday
og at der er et felt kaldet name
:
db.data.aggregate(
[
{
"$project" : {
"_id" : 0,
"name" : 1,
"birthday" : 1,
"score" : 1,
"todayDayOfYear" : {
"$dayOfYear" : new Date()
},
"birthDayOfYear" : {
"$dayOfYear" : "$birthday"
}
}
},
{
"$project" : {
"name" : 1,
"birthday" : 1,
"score" : 1,
"isBirthDay" : {
"$eq" : [
"$todayDayOfYear",
"$birthDayOfYear"
]
}
}
},
{
"$match" : {
"isBirthDay" : true,
"score" : { $gt: 100}
}
}
]
)