我在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门户上缺少任何配置吗?