MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Laravel 5 führt die Aggregation mit Mongodb in der Where-Klausel aus

Verwenden der Aggregationspipeline, in der $ne Vergleichsabfrageoperator befindet sich in $match Leitung:

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