MongoCollection::aggregate() is undefined in Heroku PHP using MongoHQ

扶醉桌前 提交于 2019-12-25 01:50:02

问题


I'm getting the following error when using MongoDB's aggregate() function in a PHP code. This code perfectly works on my local setup which is running MongoDB 2.2.3

PHP Fatal error: Call to undefined method MongoCollection::aggregate() in /app/www/page.php on line 52, referer: http://referrer.url

Code

foreach($cats as $key=>$val){
    $cats2[$val['lable']] = $myCollection->aggregate( array(
                                array('$match' => array('user_id' => $user_id )),
                                array('$unwind' =>"\$data"),
                                array('$match' => array('data.category'=> $val['category'])),
                                array('$project' => array('name'=> "\$data.name", 'id'=>"\$data.id")),
                                array('$group' => array('_id'=>'$id', 'name'=> array('$first' =>'$name'))),
                                array('$limit' => 12)
                                    ));
}

Environment

  • PHP on Heroku
  • MongoDB 2.2.4 with MongoHQ Add-on

回答1:


You have to look into your phpinfo()

If in the version you see something less than 1.3.0, then it will not work.

Go to mongo driver page download and add appropriate driver. Restart the server and it will work.



来源:https://stackoverflow.com/questions/16073893/mongocollectionaggregate-is-undefined-in-heroku-php-using-mongohq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!