Getting MongoCommandException When Trying to Create a MongoClient

Yogesh 5 Reputation points
2024-08-29T05:34:35.48+00:00

I’m getting the below error when trying to create a MongoClient using the connection string got from Azure MongoDB CosmosDB.

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='test-cosmos-account', source='admin', password=<hidden>, mechanismProperties=<hidden>}

Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Invalid key' on server test-cosmos-account-westus.mongo.cosmos.azure.com:10255. The full response is {"ok": 0.0, "errmsg": "Invalid key", "code": 18, "codeName": "AuthenticationFailed"}

I’m using the Java driver - org.mongodb.mongodb-driver-sync Version: 4.8.2

Can anyone help me on this?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,612 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 15,056 Reputation points
    2024-08-29T06:39:51.6266667+00:00

    Hi Yogesh •,

    Welcome to Microsoft Q&A forum.

    As I understand, you want to connect to Mongo Client but getting "Invalid key"

    Please double check your credentials used for connection, network settings, TLS, Drivers, etc

    Use latest drivers and version and recheck.

    Awaiting your reply.

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.