Visão geral
O mecanismo de autenticação do PLAIN permite a você utilizar seu nome de usuário e senha do Lightweight Directory Access Protocol (LDAP) para autenticar no MongoDB. A autenticação LDAP usa a PLAIN Simple Authentication and Security Layer (SASL) definida em RFC-4616.
Você pode usar esse mecanismo somente ao autenticar no MongoDB Atlas ou Enterprise Advanced.
Espaços reservados de código
Os exemplos de código nesta página usam os seguintes espaços reservados:
<ldap_username>: Seu nome de usuário LDAP.<ldap_password>: Sua senha LDAP.<cluster_url>: O endereço de rede da sua implantação MongoDB .
Para usar os exemplos de código, substitua esses espaços reservados por seus próprios valores.
LDAP (simples)
O mecanismo de autenticação do PLAIN utiliza seu nome de usuário e senha para autenticar em um servidor LDAP.
You can specify this authentication mechanism by setting the authMechanism parameter to PLAIN and including your LDAP username and password in the connection string as shown in the following sample code.
const { MongoClient } = require("mongodb"); // specify the placeholder values for your environment in the following lines const clusterUrl = "<cluster_url>"; const ldapUsername = "<ldap_username>"; const ldapPassword = "<ldap_password>"; const authMechanism = "PLAIN"; // Connection URI const uri = `mongodb+srv://${ldapUsername}:${ldapPassword}@${clusterUrl}/?authMechanism=${authMechanism}`; const client = new MongoClient(uri); // Function to connect to the server async function run() { try { // Establish and verify connection await client.db("admin").command({ ping: 1 }); console.log("Connected successfully to server"); } finally { // Ensures that the client will close when you finish/error await client.close(); } } run().catch(console.dir);
Documentação da API
Para saber mais sobre qualquer um dos métodos ou tipos discutidos nesta página, consulte a seguinte documentação da API: