0

I am getting this error when I try to use group and count.

ERROR:

InvalidArgumentException in Aggregate.php line 93: $pipeline is not a list (unexpected index: "$group")

MongoDB version: 3.2.9

jenssegers/mongodb version : 3.1.0-alpha

Here is my code.

$analytics = DB::collection('analytics')->raw( function ( $collection ) {
            return $collection->aggregate([
                '$group' => [
                    '_id'    => [ 'campaign_id' => '$campaign_id', 'type' => '$type' ],
                    'count'  => ['$sum' => 1],
                ]
            ]);
        });

I've also tried this code (enclosing aggregate in array) following solution form this issue

$analytics = DB::collection('analytics')->raw( function ( $collection ) {
            return $collection->aggregate([
                [
                    '$group' => [
                        '_id'    => [ 'campaign_id' => '$campaign_id', 'type' => '$type' ],
                        'count'  => ['$sum' => 1],
                    ]
                ],
            ]);
        });

but this time error is

UnexpectedValueException in compiled.php line 16079: The Response content must be a string or object implementing __toString(), "object" given.

TIGER
  • 2,864
  • 5
  • 35
  • 45
Code Poet
  • 147
  • 1
  • 3
  • 16

0 Answers0