Mongodb error: authentication failed [How to Solve]

Error Messages:

Database connect error:

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘root’, source=‘gateway’, password=, mechanismProperties=} Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”}.



Connect URL

mongodb://user:[email protected]:port/dbname

Add parameter authsource

For example:

mongodb://user:[email protected]:port/dbname?authSource=admin

In general, authsource is admin and can be replaced as needed

Read More: