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.

STW
  • 44,917
  • 17
  • 105
  • 161
Himani Talesara
  • 305
  • 2
  • 8
  • 15

1 Answers1

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

Zaid Masud
  • 13,225
  • 9
  • 67
  • 88
  • 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. – Himani Talesara Apr 16 '12 at 04:31
  • Does credentials authenticates a server or database – Himani Talesara Apr 16 '12 at 05:27
  • @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. – Zaid Masud Apr 18 '12 at 10:59
  • 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. – Himani Talesara Apr 19 '12 at 04:36
  • @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. – Zaid Masud Apr 19 '12 at 10:41