【发布时间】:2016-10-18 14:46:34
【问题描述】:
代码:
try {
$documentsFind = $client->$db->$collection->find([
// query
]);
if ($documentsFind) {
foreach ($documentsFind as $product) {
// code...
}
}
catch (MongoCursorException $e) {
echo "error message: ".$e->getMessage()."\n";
echo "error code: ".$e->getCode()."\n";
}
错误:
致命错误:未捕获的 MongoDB\Driver\Exception\RuntimeException: 未找到光标,光标 id: 31837896248 in ...
游标好像确实存在但是超时了?我怎样才能防止这种情况发生?
编辑添加:我尝试过:
if ($documentsFind) {
$documentsFind->immortal(true); // keep alive
foreach ($documentsFind as $product) {
// code...
}
}
但这会导致Call to undefined method MongoDB\Driver\Cursor::immortal()。
【问题讨论】:
-
第一次运行时会出现错误还是您可以加载一些条目?
-
它从数据库中获取了相当多的文档,但有时会超时。我可以用
mongod --setParameter cursorTimeoutMillis=9000000暂时绕过这个
标签: php mongodb exception cursor timeout