MongoCursorException-未找到游标(MongoDB PHP驱动程序) [英] MongoCursorException - Cursor not found (MongoDB PHP Driver)

查看:113
本文介绍了MongoCursorException-未找到游标(MongoDB PHP驱动程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

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 ...

Fatal error: Uncaught MongoDB\Driver\Exception\RuntimeException: Cursor not found, cursor id: 31837896248 in ...

似乎光标确实存在但超时了?如何防止这种情况发生?

It seems that the cursor does exist but times out? How can I prevent that from happening?

编辑后添加:我尝试做:

 if ($documentsFind) {
    $documentsFind->immortal(true); // keep alive
    foreach ($documentsFind as $product) {
    // code...
    }
  }

但这会导致对未定义方法MongoDB\Driver\Cursor :: immortal()的调用。

推荐答案

尝试像这样查询:

$documentsFind = $client->$db->$collection->find([
  // query
], ['noCursorTimeout' => true]);

find()方法传递第二个参数到 Find 类构造函数,因此您可以看到所有可用的选项此处

find() method passes the 2nd argument to the Find class constructor, so you can see all the available options here

这篇关于MongoCursorException-未找到游标(MongoDB PHP驱动程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆