我有 Mongolab 帐户,该帐户中只有一个用户。
我可以使用 MongoChef 工具连接到数据库,但是当我尝试使用 java 驱动程序 3.2.0 从 Eclipse 中连接到该数据库时,我不断遇到身份验证失败。我收到以下错误。我在 Java 7 上。
编辑 用于连接到 MongoLab 托管的 MongoDB 实例的 Java 代码。
String mongoURL = new StringBuilder().append("mongodb://").append(mongoUserName).append(":").append(mongoPassword).append("@").append(mongoServer).append(":").append(mongoPort).append("/").append(dbName).toString();
System.out.println(" The Mongo URL is " +mongoURL);
MongoClientURI uri = new MongoClientURI(mongoURL);
MongoClient mongo = new MongoClient(uri);
尝试连接时收到异常。
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while
waiting for a server that matches
ReadPreferenceServerSelector{readPreference=primary}. Client view of
cluster state is {type=UNKNOWN,
servers=[{address=ds061974.mongolab.com:61974, type=UNKNOWN,
state=CONNECTING, exception={com.mongodb.MongoSecurityException:
Exception authenticating MongoCredential{mechanism=null,
userName='xxxx', source='hidden', password=<hidden>,
mechanismProperties={}}}, caused by
{com.mongodb.MongoCommandException: Command failed with error 18:
'Authentication failed.' on server ds061974.mongolab.com:61974. The
full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication
failed." }}}]