Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication in mongodb [duplicate]

Tags:

c#

mongodb

The connection string for mongodb C# is as follows:

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

Does the connection string itself implements the authentication?

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 . Please let me know about it? I am in great need of it.Thanks in advance..

like image 627
Himani Talesara Avatar asked Apr 16 '12 04:04

Himani Talesara


1 Answers

Yes, you can.

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

And the official documentation for CSharp Driver says:

The username and password should only be present if you are using authentication on the MongoDB server. These credentials will be the default credentials for all databases. To authenticate against the admin database append "(admin)" to the username. If you are using different credentials with different databases pass the appropriate credentials to the GetDatabase method.

You can read the full documentation for connection strings on this page.

Then if you want authenticate when you get a MongoDB database instance you can use

MongoServer.GetDatabase(String, MongoCredentials)

The documentation for that is here.

like image 87
dash1e Avatar answered Nov 18 '22 05:11

dash1e