我试图找到每天所有佣金的总和,但我不知道该怎么办,以下是mongoDB文件:
"operationData" : {
"topUp" : {
"topUpId" : "20160520182653940+043000001792098779520",
"phoneNumber" : "792098779",
"commission" : 4,
}
}
}
{
"_id" : 2,
"dateTime" : ISODate("2016-06-20T13:56:53.970Z"),
"operationData" : {
"topUp" : {
"topUpId" : "20160520182653940+043000001792098779520",
"phoneNumber" : "792098779",
"commission" : 6,
}
}
}
{
"_id" : 3,
"dateTime" : ISODate("2016-06-20T13:56:53.970Z"),
"operationData" : {
"topUp" : {
"topUpId" : "20160520182653940+0430000017920987345243",
"phoneNumber" : "792098779",
"commission" : 5,
}
}
}
答案 0 :(得分:1)
您需要使用日期时间运算符ref here
名称说明
所以你可以拥有这个片段
db.operationData.aggregate([{
$group : {
_id : {
dayOfYear : {
$dayOfYear : "$dateTime"
},
year : {
$year : "$dateTime"
}
},
commission : {
$sum : "$operationData.topUp.commission"
}
}
}
])