Overview
PLAIN認証メカニズムでは、LDAP(Lightweight Directory Access Protocol)のユーザー名とパスワードを使用してMongoDB .で認証できます。LDAP認証では、RFC- で定義されている PLAIN 簡易認証とセキュリティ レイヤー(SASL) 4616が使用されます。
このメカニズムは、 MongoDB AtlasまたはMongoDB Enterprise Advancedに認証する場合にしか使用できません。
コード プレースホルダー
このページのコード例では、次のプレースホルダーを使用します。
<ldap_username>: LDAPユーザー名。<ldap_password>: LDAP パスワード。<cluster_url>: MongoDBデプロイのネットワーク アドレス。
コード例を使用するには、これらのプレースホルダーを独自の値に置き換えます。
LDAP (PLAIN)
PLAIN認証メカニズムは、ユーザー名とパスワードを使用して LDAPサーバーで認証します。
この認証メカニズムを指定するには、次のサンプル コードに示すように、authMechanism パラメータを PLAIN に設定し、 LDAPユーザー名とパスワードを接続stringに含めます。
const { MongoClient } = require("mongodb");
// specify the placeholder values for your environment in the following linesconst clusterUrl = "<cluster_url>";const ldapUsername = "<ldap_username>";const ldapPassword = "<ldap_password>";const authMechanism = "PLAIN";
// Connection URIconst uri = `mongodb+srv://${ldapUsername}:${ldapPassword}@${clusterUrl}/?authMechanism=${authMechanism}`;
const client = new MongoClient(uri);
// Function to connect to the serverasync 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);API ドキュメント
このページで説明するメソッドやタイプの詳細については、次のAPIドキュメントを参照してください。