PHP+MongoDB:未捕获的异常“MongoCursorException”,带有消息“没有这样的文件或目录”
2022-08-30 15:21:26
我正在开发一个Web应用程序,该应用程序正在尝试从PHP连接到MongoDB数据库。在90%的页面加载中,一切正常,但在其他10%中,当我尝试更新集合时,它会引发以下异常:
Fatal error: Uncaught exception 'MongoCursorException' with message 'No such file or directory' in D:\webDev\webSites\str\dev3\_global_classes\User.php:40
Stack trace:
#0 D:\webDev\webSites\str\dev3\_global_classes\User.php(40):
MongoCollection->update(Array, Array, Array)
#1 D:\webDev\webSites\str\dev3\_init\_init.php(8):
User->__construct(NULL)
#2 D:\webDev\webSites\str\dev3\index.php(3):
include('D:\webDev\webSi...')
#3 {main} thrown in D:\webDev\webSites\str\dev3\_global_classes\User.php on line 40
PHP 代码:
public function __construct($SESSIONID = null) {
User::$_users_collection = Main::$_mongo->selectCollection("users");
...
$query = array('session_id' => session_id());
$expiry = time() + Main::$_lifetime;
$data = array(
'session_id' => session_id(),
'expiry' => (string)$expiry,
'ip' => $_SERVER['REMOTE_ADDR']
);
$options = array(
'upsert' => true,
'safe' => true
);
try {
User::$_users_collection->update($query, array('$set' => $data), $options);
} catch (Exception $e) {
throw $e;
}
...
}
蒙戈版本:
Wed Oct 17 10:53:48 /usr/bin/mongos db version v2.0.7, pdfile version 4.5 starting (--help for usage)
Wed Oct 17 10:53:48 git version: 875033920e8869d284f32119413543fa475227bf
Wed Oct 17 10:53:48 build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
我的mongo集群只有一个分片,我的php版本是:5.4.4,我的mongo驱动程序版本是:1.2.12。