0
我有一個非常惱人的問題與mongo db連接。 I m using symfony2 and Mongo db php library(i don
t使用ODM)。不時無緣無故的連接失敗,出現錯誤是這樣的:Mongo db連接問題
"Failed to connect to: 54.246.115.206:27017: Previous connection attempts failed, server blacklisted"
無法連接的MongoDB,請檢查您的配置。 MongoDB 說:無法連接到:54.246.115.206:27017:以前的連接 嘗試失敗,服務器列入黑名單。
我在網上閱讀了關於這個問題,並解釋說,連接是持久的,你應該檢查連接是否超時,如果不使用它,如果它是一個新的。我使通過該代碼連接:
private function getMongoConnection($server, $user, $pass, $retry = 3) {
try {
return new \MongoClient($server, array("username" => $user, "password" => $pass, 'connect' => true));
} catch (Exception $e) {
/* Log the exception so we can look into why mongod failed later */
// \MongoClient::close();
logException($e);
}
if ($retry > 0) {
return $this->getMongoConnection($server, $user, $pass, --$retry);
}
throw new Exception("I've tried several times getting MongoClient.. Is mongod really running?");
}
我真的仍然得到上面顯示的錯誤...