lundi 11 juin 2018

MongoDB query for aggregate function retuning empty result

Following is the query i had written to get the count based on event name.

$data= DB::collection(Events::$collection)->raw(function($collection) {
    return $collection->aggregate([
    ['$match' => ['appid' => 1]],
    ['$group' => ['_id' =>['Event' =>'$Event'], 'count' =>['$sum'=>1]]]
    ]);
});

When i print the above query using laravel eloquent query logs its displays the output as follows :

Array ( 
[query] => events.aggregate([{"$match":{"appid":1}},{"$group":{"_id":{"Event":"$Event"},"count":{"$sum":1}}}]) 
[bindings] => Array ( ) [time] => 9.93 
)

DB Query As Follows:

db.events.aggregate([{"$match":{"appid":1}},{"$group":{"_id":{"Event":"$Event"},"count":{"$sum":1}}}])

The same thing if i run in NoSQLBooster for MongoDB then its retuning the result properly.

But the laravel mongodb query from the above its returning empty result. I am not getting what is the problem. Needs help.

I am using following version of laravel and mongodb.

Laravel Version : 5.4
MongoDB Version : 3.6

Thanks in Advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire