2

How do I use authentication with mongodb via the official c# driver? I can't find any API methods to authenticate, other than internal members.

2

1 Answer 1

3

Authentication credentials should be specified in your connection string, using the following connection string format:

mongodb://[username:password@]hostname[:port][/[database][?options]]

See full details here in the MongoDB C# Driver Tutorial

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

5 Comments

Thank you so much.I have tried it but it is not producing the required result. I have seen the API of C# driver . It has the 4 methods for authentication: check authentication, canAuthenticate,isAuthenticated and Authenticate , but they are internal . Does the connection string itself implements the authentication? Please let me know about it? I am in great need of it.Thank.
Does credentials authenticates a server or database
@HimaniTalesara that is correct, the connection string itself implements the authentication. It authenticates the database, not the server. MongoDB has nothing to do with server authentication, you should set up server authentication through network firewall rules only. If you find answers to your questions useful, please upvote and mark the best answer as the accepted answer.
ok.. thanks. But actual authentication takes place only when we try to use a database? This I have tested in my project. The connection string if in case have wrong values for credentials then it compiles without any error. But when I do use connection string and try to do something with this database lets say create a collection or insert a document , then it produces error. All in one, I want to say authentication comes into play when we try to use that database.
@HimaniTalesara the compiler does not verify your connection string, it can't. The connection string only gets read when you try to use the database.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.