gpt4 book ai didi

php - MongoCursorException - 未找到游标(MongoDB PHP 驱动程序)

转载 作者:可可西里 更新时间:2023-11-01 09:57:47 25 4
gpt4 key购买 nike

代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com