我目前正在開發一個連接到遠程MongoDB數據庫的Java應用程序。MongoDB試圖連接到本地主機,爲什麼?
我已經實現了身份驗證方法休耕蒙戈指南:
MongoCredential credential = MongoCredential.createScramSha1Credential(username, credentialDatabase, password.toCharArray());
MongoClient client = new MongoClient(new ServerAddress(hostname, port), Arrays.asList(credential));
mongoDatabase = client.getDatabase(database);
該應用程序正確地連接到數據庫,但我不能understand.It以及連接到遠程服務器的事情,但我不知道爲什麼它嘗試連接到本地主機:27017。
2016-03-07 16:13:29.662 INFO 12507 --- [*.*.*:25015] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:29}] to *.*.*.*:25015
2016-03-07 16:13:29.687 INFO 12507 --- [*.*.*:25015] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=*.*.*.*:25015, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 3]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, roundTripTimeNanos=24485426}
2016-03-07 16:13:30.062 INFO 12507 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2016-03-07 16:13:30.220 INFO 12507 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
所以,我怎麼能告訴它我不希望連接到本地主機?
感謝
你可以張貼'hostname'字符串? –
這應該回答你的問題。 https://docs.mongodb.org/manual/reference/program/mongod/#bin.mongod – user2263572
主機名字符串是我的服務器的IP地址 – adenaud