我坚持的东西,需要你的帮助。 我想对下面的集合执行mongo聚合查询,以便我可以从boxWeight1和boxWeight2中获取每个子数组列表的最大总和权重,即sum+=max[boxWeight1,boxWeight2] for each array item in boxList array
,而其他字段应该按照它的样子投影,但使用不同的键名称。在Mongo总结每个数组元素后发现最大从每个
收藏是有点像这样...
{
_id: '',
email: '[email protected]',
number: 12345,
boxDetail: {
boxname: 'package_yugal',
boxList: [
{
boxWeight1: '4.0', //this is max here. so it will be added
boxWeight2: '2.0'
}.
{
boxWeight1: '4.0',
boxWeight2: '8.0' //this is max here. so it will be added
}
{
boxWeight1: '0.0',
boxWeight2: '2.0' //this is max here. so it will be added
}
]
}
}
所以对于执行查询后,上述集合的结果应该是有点这样的:
{
'User Mail': '[email protected]',
'Order Number': '12345',
'Total Weight': '14.0' // 4 + 8 + 2
}
我希望你明白我的问题。 在此先感谢。
是的,我只是试过这个。我已经在上面发布了我的答案。 感谢您的回答。现在我确信我的查询在某种程度上是正确的。 –