我在azure订阅中创建了一个Cosmos DB(带有Mongo API)。
现在尝试使用我现有的代码连接到CosmosDB以连接到mongo DB。我只是更改代码以创建mongo客户端。
我使用从Cosmos DB->连接字符串中获得的连接字符串创建了Mongo Client。
微软提供的Cosmos DB也可以使用相同的功能进行试用。
可以从https://azure.microsoft.com/en-us/try/cosmosdb创建。
但不适用于我在订阅中创建的Cosmos DB。
我得到以下错误:
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='[myusername]', source='admin', password=<hidden>, mechanismProperties={}}
at com.mongodb.connection.SaslAuthenticator.wrapInMongoSecurityException(SaslAuthenticator.java:157) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:37) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:66) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:44) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:162) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:44) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:109) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:46) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) [mongo-java-driver-3.4.2.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
Caused by: com.mongodb.MongoCommandException: Command failed with error 11: 'Database account is not found' on server [my cosmosdb name].documents.azure.com:10255. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 11, "errmsg" : "Database account is not found", "$err" : "Database account is not found" }
at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:121) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:37) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:63) ~[mongo-java-driver-3.4.2.jar:?]
... 9 more
我在Azure门户上缺少任何配置吗???
最佳答案
您可以禁用防火墙,但是这会使您很容易受到攻击。更好地启用对工作站的访问:
转到名为防火墙和虚拟网络的Azure Cosmos DB菜单。
选择选定的网络
单击建议的选项+添加我的当前IP(xx.xx.xx.xx),这基本上会自动将您工作站的Internet IP添加到MongoDB / CosmosDB允许的客户端IP中。
转到名为“快速入门”的Azure Cosmos DB菜单。在那里,您将获得与数据库连接的替代方法。
关于mongodb - Cosmos DB错误:com.mongodb.MongoCommandException:命令失败,错误11:“未找到数据库帐户”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51418709/