Laravel 5在where子句上使用mongodb执行聚合

时间:2016-01-07 06:33:10

标签: php mongodb laravel-5

Laravel 5 Eloquent sum of multiplied columns for mongo DB

这是我之前的问题,在@Alex的帮助下解决了,现在我需要添加$field != '0'

的where子句

我在这里遇到困难但是我仍然没有选择从这里获得帮助。

由于

1 个答案:

答案 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']]
                    ]
                ]
            ]
        ]);
    })