0
MongoDb를 연결하고 데이터를 쓰는 Java 프로그램을 작성합니다. 예를 들어 MongoDb를 192.168.1.95에 설치하고 해당 프로그램을 내 서버에서 실행합니다. 다음 코드를 사용할 때 :Java with MongoDb IP 연결 문제
MongoClient mongo = new MongoClient("localhost", 27017);
아무런 문제가 없습니다. 그러나, 나는
MongoClient mongo = new MongoClient("192.168.1.95", 27017);
그것은 항상 나를 위해 예외를 던질 사용
Exception in thread "main" com.mongodb.MongoException: unauthorized
at com.mongodb.CommandResult.getException(CommandResult.java:100)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:134)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:142)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:183)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at com.starscriber.mongoCluster.Main.main(Main.java:29)
왜 내가 대신 "localhost"를의 정확히 IP를 사용할 수 없습니다 ?? 그리고 MongoDb에 로그인 할 때 사용자 이름과 암호가 필요 없다는 것을 확신합니다.
Ok. 알았다. 왜냐하면 나는 keyFile을 사용하므로 auth = true입니다. – user3019299