I'm working on a web application which is trying to connect to a MongoDB database from PHP. In the 90% of page loads everything works fine, but in the other 10% it throws the following exception when I try to update a collection:
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 code:
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;
}
...
}
Mongo version:
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
My mongo cluster has only one shard, my php version is: 5.4.4, and my mongo driver version is: 1.2.12.
$e->getCode()
in the catch block. – Omnifarious