0
"payments": [
{
"_id": "57bea755acfbfc4e37c3dfdf",
"user": "57b1c3d2d591a46848c25f45",
"transferred_amount": 10,
"transaction_type": "refund",
"reason": "#1968 shop box refunded",
"__v": 0
},
{
"_id": "57beb883acfbfc4e37c3dfe0",
"user": "57b1c3d2d591a46848c25f45",
"transferred_amount": 10,
"transaction_type": "payout",
"reason": "#1968 shop box refunded",
"__v": 0
}
]
這是我的db數據。
Model.aggragate().project({
paid_out_amount: {
$sum: {
$cond: [{
$eq: ['$payments.transaction_type', 'payout']
}, 0, '$payments.transferred_amount']
}
}
})
這是我的節點代碼來獲取這些數據。我試圖單獨付款付款金額並將其存儲到一個字段中。這裏$ cond總是返回零。誰能幫我嗎。