我想弄清楚为什么我无法连接到托管在MongoClient()
上的IP
。我使用下面的代码连接到另一个IP
并访问其DB
和Collections
<?php
$username = 'root';
$password = '';
$conn = new MongoClient("mongodb://SYSTEMIP:27017", array("username" => $username, "password" => $password));
$database = $conn->testdb; //Creating New Database
$collection = $database->users; //Calling users collection
?>
打印的例外是MongoConnectionException: Failed to connect to: SYSTEM:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
。
我需要在系统上做些什么改变吗? {I}已正确安装在我需要连接的IP上。如果我做错了,请纠正我。
感谢。
答案 0 :(得分:0)
MongoDB 2.6附带bindIp配置集。查看你的配置。
http://docs.mongodb.org/manual/reference/configuration-options/#net.bindIp
另外,检查27017是否允许TCP。检查防火墙或其他限制。