私は何かに悩まされており、あなたの助けが必要です。 以下のコレクションでmongo集約クエリを実行して、boxWeight1とboxWeight2の各サブアレイリストのMax of Sum of totalを取得できるようにします。つまり、sum+=max[boxWeight1,boxWeight2] for each array item in boxList array
であり、他のフィールドはそれぞれ別のKeyで投影する必要があります名前。私はあなたが私の質問を理解している願っていますMongo In各配列要素の最大値を求めた後に
{
'User Mail': '[email protected]',
'Order Number': '12345',
'Total Weight': '14.0' // 4 + 8 + 2
}
:
コレクションだから、クエリを実行した後に上記のコレクションの結果は多少このようにする必要があり...多少このよう
{
_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
}
]
}
}
です。 ありがとうございます。
ええ、私はこれだけのように試しました。私は上記の私の答えを掲載しました。 お返事ありがとうございます。今私は質問が正しい方向にあると確信しています。 –