我在UserId和Aggregation Framework之后得到了这个结果。我想创建一个单独的文档与"合并"阵列foo和能力
我的聚合
{
"result" : [
{
"_id" : {
"userId" : ObjectId("53bab268ceee750615240269")
},
"foo" : [
"0.109",
"0.105",
"0.50",
"0.1",
"foo"
],
"ability" : [
"Power",
"Energy",
"ReactiveEnergy",
"Stamina",
"bar"
]
}
],
"ok" : 1
}
我喜欢
{
"result" : [
{
"_id" : {
"userId" : ObjectId("53bab268ceee750615240269")
},
"fooFinal" : [
{"0.109",power}
{"0.105",Energy }
{"0.50",ReactiveEnergy }
{"0.1",Stamina }
{"foo",bar}
],
}
],
"ok" : 1
}
我想使用类似的$ each,但我不能在聚合
中使用它答案 0 :(得分:4)
尝试在$ group中执行此操作
$group:{
_id:{'userId':'$userId'},
'fooFinal' : {$push:{
foo:'$foo',
ability:'$ability'}
}
}