我有一个json
{
"_id": "560253036e1316b021b90a55",
"mood": "meh",
"timestamp": "092315"
},
{
"_id": "5602564b6e1316b021b90a56",
"mood": "happy",
"timestamp": "092315"
}
将在mongodb中使用aggreagte进行转换,我的工作代码是
`db.mood.aggregate(
[{
$match : {
timestamp : sixDigitDate //its a simple function that returns 6 days
}
},
{
$group : {
_id : "$mood",
total : {
$sum : 1
}
}
}
]
)
`
以这样的格式输出json
[
{
"_id": "meh",
"total": 1
},
{
"_id": "happy",
"total": 1
}
]
我想要完成的是让json像这样的格式输出:
{ //the ID will be the date.
date : 092315,
"meh" : 1,
"happy" : 1
}
{
date : 092317,
"meh" : 2,
"happy" : 3
}
关于从哪里开始的任何提示?