PHP Codeigniter with Mongo 4.4.2 Aggregate Issue

I’m Using Aggreate function with following code in my project

 $res[] = array(
              '$match' => array('WIN_BALANCE' => array('$gte' => 1)),
             '$group' => array('_id' => '$USER_ID', 'total' => array('$sum' => 'WIN_BALANCE')),
             '$sort' => array('total' => -1),
             [$cursor' => ['batchSize' => 0 ]]
         );
      $this->mongo_db->aggregate('user',$res);

But getting below error.

Aggregation operation failed: localhost:27017: The ‘cursor’ option is required, except for aggregate with the explain argument.

I have tired with [‘explain’ => true ] also.

I was searching many forums didn’t get any solutions.

Can you please me out of this.

Thanks in advance

1 Like

Hi Everyone,
Do you have any solution for this reported issue

Hi @siva_r,

Did you find a solution to your issue? If not, what version of the MongoDB PHP driver and MongoDB server are you currently using?

MongoDB 3.6 and newer servers always return aggregation results using a cursor. This should be automatically handled for you when using a compatible driver. Please see MongoDB Compatibility: PHP Driver for a table indicating the range of supported PHP driver & server combinations.

Updating to a newer driver version should resolve your issue, but as with any upgrade please review the release notes in case there are any API or compatibility changes from the version you are currently using.

Regards,
Stennie

1 Like