Cosmos DB错误:com.mongodb.MongoCommandException:命令失败,错误11:“未找到数据库帐户”

时间:2018-07-19 09:14:01

标签: mongodb authentication ssl azure-cosmosdb

我在Azure订阅中创建了一个Cosmos DB(带有Mongo API)。

现在尝试使用我现有的代码连接到CosmosDB以连接到mongo DB。我只是更改代码以创建mongo客户端。

我使用从Cosmos DB->连接字符串中获得的连接字符串创建了Mongo Client。

同一件事与Microsoft提供的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门户上缺少任何配置吗?

1 个答案:

答案 0 :(得分:0)

您可以禁用防火墙,但是这会使您非常容易受到攻击。更好地启用对您工作站的访问:

  1. 转到名为防火墙和虚拟网络的Azure Cosmos DB菜单。

Firewall and virtual networks

  1. 选择选定的网络

  2. 单击建议的选项 +添加我当前的IP(xx.xx.xx.xx),这基本上会自动将您的工作站的Internet IP添加到MongoDB / CosmosDB允许的客户端IP中

  3. 转到名为快速入门的Azure Cosmos DB菜单。在那里,您将获得与数据库连接的替代方法。