美文网首页
mongoDB The ‘cursor’ option is r

mongoDB The ‘cursor’ option is r

作者: 直接注册 | 来源:发表于2019-12-11 10:09 被阅读0次

当mongodb的版本大于3.5,在使用aggregate查询时,需要有cursor参数。

Thinkphp5的mongodb驱动存在这个bug,修复步骤:

1,找到Builder.php,在aggregate方法里添加一行

$cmd = [

      'aggregate'    => $options['table'],

      'allowDiskUse' => true,

      'pipeline'    => $pipeline,

      'cursor' => (object)[]

  ];

2,找到Query.php,在aggregate方法里面修改

public function aggregate($aggregate, $field)

{

    $result = $this->cmd('aggregate', [$aggregate, $field]);

    // return isset($result[0]['result'][0]['aggregate']) ? $result[0]['result'][0]['aggregate'] : 0;

    return isset($result[0]['aggregate']) ? $result[0]['aggregate'] : 0;

}

这样就可以正常使用mongodb驱动里的聚合方法了。

相关文章

网友评论

      本文标题:mongoDB The ‘cursor’ option is r

      本文链接:https://www.haomeiwen.com/subject/zaqogctx.html