我正在开发一个尝试从 PHP 连接到 MongoDB 数据库的 Web 应用程序。在 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集群只有一个shard,我的php版本是:5.4.4,我的mongo驱动版本是:1.2.12。