0
东西我曾尝试:通过Android应用程序访问MongoDB。不工作
InetAddress address = InetAddress.getByName("MyPCName");
MongoClientOptions.Builder builder = MongoClientOptions.builder().connectTimeout(3000);
MongoClient mongo = new MongoClient(new ServerAddress(address.getHostAddress(), 3001), builder.build());
try {
mongo.getAddress();
} catch (Exception e) {
System.out.println("Mongo is down");
mongo.close();
}
第二个尝试:
InetAddress address = InetAddress.getByName("MyPCName");
MongoClientURI uri = new MongoClientURI("mongodb://"+address.getHostAddress()+":27017/"+TEST_SKETCH_APP);
MongoClient instance = MongoDatabaseConnection.getInstance(uri);
try {
instance .getAddress();
} catch (Exception e) {
System.out.println("Mongo is down");
instance .close();
}
防火墙中配置正确:
netsh advfirewall firewall add rule name="Allowing mongod" dir=in action=allow program=" C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe"
但仍当我尝试连接到做插入操作的我得到这个错误信息:
Timed out after 3000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=192.168.138.1:3001, type=Unknown, state=Connecting}]
我正在做一个AsyncTask的保存操作。我的mongo数据库服务器正在“MyPCName”计算机中运行。我的Mongodb配置也绑定ip评论。我也尝试了绑定IP来保持这个bind_ip = 127.0.0.1,***.***.***.*,0.0.0.0
'*'标记是我得到的IP地址,当我做address.getHostAddress()
。
我现在卡在这里。
不想使用mongolab数据库,希望在本地计算机中拥有一个数据库,并稍后将其作为服务器。 – Nagendra555