调用未定义的方法MongoDB :: find()

时间:2014-07-01 00:49:36

标签: php mongodb database

以下是代码:

require_once("config.php");
class xy {
// List all the ingredients in a container
public function objectsInContainer($container) {
    global $mongo, $box;
    $hereUGo = $mongo->selectDB($box);
    $cursor = $hereUGo->find();
    return $cursor;
}
}

在config.php中,有'

$mongo = new Mongo();
$box = $mongo->selectDB($box);

PHP告诉我PHP Fatal error: Call to undefined method MongoDB::find()。我做错了什么?

1 个答案:

答案 0 :(得分:2)

MongoDB没有方法find。您必须在搜索之前选择集合。

http://www.php.net/manual/en/class.mongocollection.php