mongoDB异步驱动程序java - 无法连接身份验证

时间:2016-08-02 13:44:45

标签: mongodb mongodb-java

最近,我们已将mongoDB端口35489以及authenticationroles更新到数据库。
我已为用户授予了readWritereadWriteAnyDatabase个角色,并且可以从我们的c#编码成功连接,并在web.config中提及它。

我的web.config:

<add key="MongoConnectionString" value="mongodb://readWriteUser:********@192.168.1.225:35489/admin" />

现在,我的问题是uanble to connect mongoDB java async driver来自public static final String DEFAULT_URI = "mongodb://readWriteUser:******@localhost:35489/"; public static synchronized ConnectionString getConnectionString() { if (connectionString == null) { connectionString = new ConnectionString(DEFAULT_URI); } return connectionString; } public static synchronized MongoClient getMongoClient() { if (mongoClient == null) { mongoClient = MongoClients.create(getConnectionString()); } return mongoClient; } 并且它会抛出异常

例外

连接到服务器localhost时监视器线程中的异常:35489 com.mongodb.MongoSecurityException:异常验证MongoCredential {mechanism = null,userName =&#39; AdminAllDatabases&#39;,source =&#39; admin&#39;, com.mongodb.connection.SatlAuthenticator.authenticate(SaslAuthenticator.java:61)中的com,密码=,机制属性= {}}位于com.mongodb.connection.InternalStreamConnectionInitializer的com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32) .authenticateAll(InternalStreamConnectionInitializer.java:99)位于com.mongodb.connection上的com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)的com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:44)。 java.lang.Thread.run中的DefaultServerMonitor $ ServerMonitorRunnable.run(DefaultServerMonitor.java:127)(未知来源)引起:com.mongodb.MongoCommandException:命令失败,错误18:&#39;认证通知失败。&#39;在服务器localhost:35489。完整的回答是{&#34; ok&#34; :0.0,&#34;代码&#34; :18,&#34; errmsg&#34; :&#34;身份验证失败。&#34; com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170)at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123)at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java: 32)at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:99)at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:58)... 6个常见帧被省略

我的异步java驱动程序代码:

{{1}}

我们已尝试使用localhost和ip地址,但似乎没有任何效果。

有人能建议我这样做的正确方法吗?

0 个答案:

没有答案