Laravel 5在where子句上使用mongodb执行聚合 [英] Laravel 5 execute aggregation with mongodb on where clause

查看:561
本文介绍了Laravel 5在where子句上使用mongodb执行聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Laravel 5 mongo乘以列的有效总和数据库

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

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.

谢谢

推荐答案

使用聚合管道,其中

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

这篇关于Laravel 5在where子句上使用mongodb执行聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆