代码:
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";
}
错误:
Fatal error: Uncaught MongoDB\Driver\Exception\RuntimeException: Cursor not found, cursor id: 31837896248 in ...
好像游标确实存在但是超时了?我怎样才能防止这种情况发生?
编辑添加:我尝试这样做:
if ($documentsFind) {
$documentsFind->immortal(true); // keep alive
foreach ($documentsFind as $product) {
// code...
}
}
但这会导致 Call to undefined method MongoDB\Driver\Cursor::immortal()
。
最佳答案
尝试这样查询:
$documentsFind = $client->$db->$collection->find([
// query
], ['noCursorTimeout' => true]);
find()
方法将第二个参数传递给 Find
类构造函数,因此您可以看到所有可用选项 here
关于php - MongoCursorException - 未找到游标(MongoDB PHP 驱动程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37870115/