I have Java SpringBoot application connecting to a database in MongoDB enterprise 7.x version. The application runs in OpenShift container platform. Previously it used in PCF Cloud. I have observed below error occurring randomly.
When i try to test using postman, i randomly get this error. During subsequent attempt to run the same test, connection is successful.
Any idea what needs to be changed so that the application won’t get this error?
=============
Connection String:
mongodb://xxxxxxx:xxxxxxx@xxxxxxx,xxxxxxx,xxxxxxx/dbname?replicaSet=rs_replicaname&authMechanism=PLAIN&authSource=$external
======
ERROR:
Waiting for server to become available for operation with ID 1069229. Remaining time: 29999 ms. Selector: ReadPreferenceServerSelector{readPreference=primary}, topology description: {type=REPLICA_SET, servers=[{address=xxxxxxx, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=PLAIN, userName=‘xxxxxxxxxxxxx’, source=‘$external’, password=, mechanismProperties=}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server xxxxxxx. The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”, “$clusterTime”: {“clusterTime”: {“$timestamp”: {“t”: 1752859399, “i”: 1}}, “signature”: {“hash”: {“$binary”: {“base64”: “xxxxxxxxxxxx”, “subType”: “00”}}, “keyId”: xxxxxxxxxx}}, “operationTime”: {“$timestamp”: {“t”: 1752859399, “i”: 1}}}}}, {address=xxxxxxxxxxxxxx, type=REPLICA_SET_SECONDARY, roundTripTime=37.5 ms, state=CONNECTED}, {address=xxxxxxxxxxxx, type=REPLICA_SET_SECONDARY, roundTripTime=20.5 ms, state=CONNECTED}, {address=xxxxxxxxxxxxx, type=REPLICA_SET_SECONDARY, roundTripTime=24.1 ms, state=CONNECTED}, {address=xxxxxxxxx, type=REPLICA_SET_SECONDARY, roundTripTime=0.6 ms, state=CONNECTED}, {address=xxxxxxxxxxx, type=REPLICA_SET_SECONDARY, roundTripTime=32.0 ms, state=CONNECTED}]