Reputation: 774
Laravel 5 Eloquent sum of multiplied columns for mongo DB
This was my previous question and it got solved with the help of @Alex, now i need to add a where clause of $field != '0'
Here I am stuck I tried with the match but still I have no option left to get help from here.
Thanks
Upvotes: 0
Views: 1464
Reputation: 103425
Using the aggregation pipeline where the $ne
comparison query operator is in the $match
pipeline:
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']]
]
]
]
]);
})
Upvotes: 2