我正在尝试将我的mongo群集转移到mongodb-atlas。 当我尝试连接到mongoDB时,它正在进行连接(我可以从atlas日志和php-mongodb驱动程序中看到),但它会立即抛出错误。
我在php-driver日志中找到了以下内容
2018-04-27 02:27:02 :: IO (FINE): getting reply
2018-04-27 02:27:02 :: IO (FINE): getting cursor header
2018-04-27 02:27:02 :: CON (FINE): Setting the stream timeout to -1.000000
2018-04-27 02:27:02 :: MongoCursorTimeoutException (ERROR): <atlashost:port>: Read timed out after reading 0 bytes, waited for -1.000000 seconds`
当它连接到我自己的集群时,相同的代码运行正常。
版本和其他一切都是一样的。版本:3.6
我陷入了调试困境,但找不到任何东西。
任何帮助都将不胜感激。
以下是显示连接流程的代码:
final class mongoConnection {
static function createConnection() {
$ctx = stream_context_create(array(
"ssl" => array(
"verify_peer" => false
))
);
self::$connection = new MongoClient("mongodb://user:password@host:port/admin&ssl=true",array("replicaSet" => 'replicaNamw'),array("context" => $ctx));
return self::$connection;
}
}
function connectMongoDb()
{
$mongo = mongoConnection::createConnection();
$m = $mongo->getConnection();
$db = $m->selectDB('DATABASE');
return $db;
}
$mongoDb = $this->connectMongoDb();
$collection->find()->sort(array('_id' => -1))->limit(100); //this is one of the line where I am getting error in my application
var_dump(self::$connection)
object(MongoClient)[21]
public 'connected' => boolean true
public 'status' => null
protected 'server' => null
protected 'persistent' => null
错误:
( ! ) MongoCursorTimeoutException: <host>:<port>: Read timed out after reading 0 bytes, waited for -1.000000 seconds in <filename> on line 33