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();
}
2回目の試行:
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"
をしかし、それでも、私は挿入操作のIを行うために接続しようとすると、このエラーメッセージが表示されます:
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 dbサーバは "MyPCName"コンピュータで動作しています。私のMongodbの設定にはバインドされたIPもコメントされています。そして私はこれを保つためにバインドIPを試みましたbind_ip = 127.0.0.1,***.***.***.*,0.0.0.0
address.getHostAddress()
を実行したときに '*'マークが表示されます。
ここにはまった。
mongolabデータベースを使用したくない、ローカルコンピュータにデータベースを持ち、それを後でサーバーにしたい。 – Nagendra555