LDAP
On this page
Overview
The PLAIN authentication mechanism allows you to use your Lightweight Directory Access Protocol (LDAP) username and password to authenticate to MongoDB. You can use this mechanism only when authenticating to MongoDB Enterprise Advanced.
Tip
PLAIN Authentication
LDAP authentication uses the PLAIN Simple Authentication and Security Layer (SASL) defined in RFC-4616.
Code Placeholders
The code examples on this page use the following placeholders:
<username>
: Your LDAP username.<password>
: Your LDAP password.<hostname>
: The network address of your MongoDB deployment.<port>
: The port number of your MongoDB deployment. If you omit this parameter, the driver uses the default port number (27017
). You don't need to specify a port when connecting to a MongoDB Atlas cluster.<authenticationDb>
: The MongoDB database that contains the user's LDAP credentials.- If you omit this parameter, the driver uses the default database (
admin
).
To use the code examples on this page, replace these placeholders with your own values.
Using PLAIN Authentication in Your Application
You can specify the PLAIN
authentication mechanism and supply your LDAP credentials
either by
using a MongoCredential
object or as part of the connection string.
Select the Connection String or MongoCredential tab to
see the corresponding syntax:
var mongoClient = new MongoClient( "mongodb://<username>:<password>@<hostname>[:<port>]/?authSource=<authenticationDb>" + "&authMechanism=PLAIN");
var credential = MongoCredential .CreatePlainCredential("<authenticationDb>", "<username>", "<password>"); var settings = MongoClientSettings.FromConnectionString("<connection string>"); settings.Credential = credential; var mongoClient = new MongoClient(settings);
API Documentation
To learn more about any of the methods or types discussed on this page, see the following API documentation: