Anda dapat menggunakan kerangka kerja agregasi dengan $dayOfYear
operator. Saya berasumsi bahwa tanggal lahir disimpan di bidang birthday
dan ada bidang bernama 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}
}
}
]
)