Laravel 5 Eloquent sum of multiplied columns for mongo DB
这是我之前的问题,在@Alex的帮助下解决了,现在我需要添加$field != '0'
我在这里遇到困难但是我仍然没有选择从这里获得帮助。
由于
答案 0 :(得分:1)
使用 $ne
比较查询运算符位于 $match
管道中的聚合管道:
DB::connection($this->MongoSchemaName)
->collection($this->InvoicesTable)
->raw(function($collection) use ($customer){
return $collection->aggregate([
['$match' => [
'ContactID' => (int)$customer->ContactID,
'Type' => 'PAYMENT',
'AmountDue' => [ '$ne' => 0 ]
]
],
['$group' => [
'_id' => '$ContactID',
'TotalInBaseCurrency' => [
'$sum' => ['$multiply' => ['$Total', '$CurrencyRate']]
]
]
]
]);
})