3zz*_*zzy 2 php timeout exception cursor mongodb
代码:
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";
}
Run Code Online (Sandbox Code Playgroud)
错误:
致命错误:未捕获的MongoDB \ Driver \ Exception \ RuntimeException:未找到游标,游标ID:31837896248 ...
似乎光标确实存在但超时了?如何防止这种情况发生?
编辑添加:我尝试做:
if ($documentsFind) {
$documentsFind->immortal(true); // keep alive
foreach ($documentsFind as $product) {
// code...
}
}
Run Code Online (Sandbox Code Playgroud)
但这导致了Call to undefined method MongoDB\Driver\Cursor::immortal()。
尝试这样查询:
$documentsFind = $client->$db->$collection->find([
// query
], ['noCursorTimeout' => true]);
Run Code Online (Sandbox Code Playgroud)
find()方法将第二个参数传递给Find类构造函数,因此您可以在此处查看所有可用选项
| 归档时间: |
|
| 查看次数: |
1769 次 |
| 最近记录: |