2

I have configured Java MongoDB Client to use MongoCredential. Unfortunately when I access to a server that does not configured to use an authentication I get authentication failed exception:

Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server …. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }

I do expect this exception when a server is configured to use an authentication and when Java MongoDB Client but not in this case.

Is it possible to configure Java MongoDB Client not to fail when access to a server not configured to use an authentication?

1 Answer 1

1

I am afraid not, your client does not know whether the server has auth enabed or not.
Your client connection code should match the auth parameters from the server, otherwise it fails.

What I did in this case, was to create a connection function which accepts auth credentials, when credentials are passed, used them - create the connection with auth credentials, otherwise no - create the connection with no auth credentials.

In this case, you should know what server has auth enabled

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.