7

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..

4

1 回答 1

9

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.

于 2012-04-16T04:49:09.760 回答