【发布时间】:2022-11-11 01:04:27
【问题描述】:
我在聚合管道的第一阶段有这个结果数组,使用$match:
[
{ a: 1, b: 2 },
{ a: 3, b: 4 }
]
现在我想总结所有的 A 和 B 并且仍然有它们,所以我会得到这样的结果:
{
total_sum: 10,
items: [...] // first and second objects ofcourse
}
我尝试过$group 和$push,但是,push 只从对象中推送特定字段,我需要命名 A 和 B,而不是只解析所有字段。
我该怎么做?
【问题讨论】:
-
这是你试图达到的目标吗? Sample Mongo Playground。只是不明白
I need to name A and B, instead just of parse all of them.是什么意思。 -
是的,我只是在寻找这个
$$ROOT!
标签: mongodb nosql aggregation-framework aggregation