【发布时间】:2015-08-17 21:07:02
【问题描述】:
自从我将 Mongo PHP Driver 从 1.5.8 升级到 1.6.0 后,我在使用 PHP MongoCursor 时遇到了问题
以下代码在 1.5.8 版本下运行良好,但在 1.6 版本下崩溃
PHP 版本是 5.5.21.,Apache 版本是 Apache/2.4.10 (Ubuntu)
$mongoClient = new \MongoClient($serverUrl, ['readPreference'=>\MongoClient::RP_NEAREST]);
$database = $mongoClient->selectDB($dbName);
$collection = $database->selectCollection($collectionName);
// count() works fine and returns the right nb on documents
echo '<br/>count returned '.$collection->count();
// find() exectues with no error...
$cursor = $collection->find();
$documents = [];
// ...and hasNext() crashes with the Excetion below
while($cursor->hasNext()){$documents[] = $cursor->getNext();}
return $documents;
因此 hasNext() 调用会因这条消息而崩溃:
CRITICAL: MongoException: MongoCursor 对象没有被其构造函数正确初始化(未捕获的异常)...
我做错了吗? 谢谢你的帮助!
【问题讨论】:
-
我也有同样的问题
-
@LeonardoDelfino:请参阅下面的回复。我很想知道这对您来说是否也很容易重现,以及您是否愿意进一步调试它。