File tree Expand file tree Collapse file tree 14 files changed +518
-363
lines changed Expand file tree Collapse file tree 14 files changed +518
-363
lines changed Original file line number Diff line number Diff line change 11name = " node"
2- toc_landing_pages = [" /crud" , " /crud/read-operations" , " /crud/write-operations" ]
2+ # toc_landing_pages = ["/crud", "/crud/read-operations", "/crud/write-operations"]
33
44[constants ]
55version = 4.0
Original file line number Diff line number Diff line change 1+ // ignored first line
2+ const { MongoClient } = require ( "mongodb" ) ;
3+ const fs = require ( "fs" ) ;
4+
5+ // specify the placeholder values for your environment in the following lines
6+ const username = encodeURIComponent ( "<username>" ) ;
7+ const password = encodeURIComponent ( "<password>" ) ;
8+ const clusterUrl = "<MongoDB cluster url>" ;
9+
10+
11+ // Replace the following with your MongoDB deployment's connection
12+ // string.
13+ const uri =
14+ `mongodb+srv://${ username } :${ password } @${ clusterUrl } /?authMechanism=${ authMechanism } &tls=true&tlsCertificateKeyFile=${ clientPEMFile } ` ;
15+
16+ // Create a new MongoClient
17+ const client = new MongoClient ( uri ) ;
18+
19+ // Function to connect to the server
20+ async function run ( ) {
21+ try {
22+ // Connect the client to the server
23+ await client . connect ( ) ;
24+
25+ // Establish and verify connection
26+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
27+ console . log ( "Connected successfully to server" ) ;
28+ } finally {
29+ // Ensures that the client will close when you finish/error
30+ await client . close ( ) ;
31+ }
32+ }
33+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change 1+ // ignored first line
2+ const { MongoClient } = require ( "mongodb" ) ;
3+
4+ // specify the placeholder values for your environment in the following lines
5+ const username = encodeURIComponent ( "<username>" ) ;
6+ const password = encodeURIComponent ( "<password>" ) ;
7+ const clusterUrl = "<MongoDB cluster url>" ;
8+
9+ const authMechanism = "DEFAULT" ;
10+
11+ // Replace the following with your MongoDB deployment's connection
12+ // string.
13+ const uri =
14+ `mongodb+srv://${ username } :${ password } @${ clusterUrl } /?authMechanism=${ authMechanism } ` ;
15+
16+ // Create a new MongoClient
17+ const client = new MongoClient ( uri ) ;
18+
19+ // Function to connect to the server
20+ async function run ( ) {
21+ try {
22+ // Connect the client to the server
23+ await client . connect ( ) ;
24+
25+ // Establish and verify connection
26+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
27+ console . log ( "Connected successfully to server" ) ;
28+ } finally {
29+ // Ensures that the client will close when you finish/error
30+ await client . close ( ) ;
31+ }
32+ }
33+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change 1+ // ignored first line
2+ const { MongoClient } = require ( "mongodb" ) ;
3+
4+ // specify the placeholder values for your environment in the following lines
5+ const username = encodeURIComponent ( "<username>" ) ;
6+ const password = encodeURIComponent ( "<password>" ) ;
7+ const clusterUrl = "<MongoDB cluster url>" ;
8+
9+ const authMechanism = "SCRAM-SHA-1" ;
10+
11+ // Replace the following with your MongoDB deployment's connection
12+ // string.
13+ const uri =
14+ `mongodb+srv://${ username } :${ password } @${ clusterUrl } /?authMechanism=${ authMechanism } ` ;
15+
16+ // Create a new MongoClient
17+ const client = new MongoClient ( uri ) ;
18+
19+ // Function to connect to the server
20+ async function run ( ) {
21+ try {
22+ // Connect the client to the server
23+ await client . connect ( ) ;
24+
25+ // Establish and verify connection
26+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
27+ console . log ( "Connected successfully to server" ) ;
28+ } finally {
29+ // Ensures that the client will close when you finish/error
30+ await client . close ( ) ;
31+ }
32+ }
33+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change 1+ // ignored first line
2+ const { MongoClient } = require ( "mongodb" ) ;
3+
4+ // specify the placeholder values for your environment in the following lines
5+ const username = encodeURIComponent ( "<username>" ) ;
6+ const password = encodeURIComponent ( "<password>" ) ;
7+ const clusterUrl = "<MongoDB cluster url>" ;
8+
9+ const authMechanism = "SCRAM-SHA-256" ;
10+
11+ // Replace the following with your MongoDB deployment's connection
12+ // string.
13+ const uri =
14+ `mongodb+srv://${ username } :${ password } @${ clusterUrl } /?authMechanism=${ authMechanism } ` ;
15+
16+ // Create a new MongoClient
17+ const client = new MongoClient ( uri ) ;
18+
19+ // Function to connect to the server
20+ async function run ( ) {
21+ try {
22+ // Connect the client to the server
23+ await client . connect ( ) ;
24+
25+ // Establish and verify connection
26+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
27+ console . log ( "Connected successfully to server" ) ;
28+ } finally {
29+ // Ensures that the client will close when you finish/error
30+ await client . close ( ) ;
31+ }
32+ }
33+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change 1+ // ignored first line
2+ const { MongoClient } = require ( "mongodb" ) ;
3+ const fs = require ( "fs" ) ;
4+
5+ const username = encodeURIComponent ( "<client certificate distinguished name>" ) ;
6+ const clusterUrl = "<MongoDB cluster url>" ;
7+ const clientPEMFile = encodeURIComponent (
8+ "<path to the client pem certificate file>" ,
9+ ) ;
10+ const authMechanism = "MONGODB-X509" ;
11+
12+ // Replace the following with your MongoDB deployment's connection
13+ // string.
14+ const uri =
15+ `mongodb+srv://${ username } @${ clusterUrl } /?authMechanism=${ authMechanism } &tls=true&tlsCertificateKeyFile=${ clientPEMFile } ` ;
16+
17+ // Create a new MongoClient
18+ const client = new MongoClient ( uri ) ;
19+
20+ // Function to connect to the server
21+ async function run ( ) {
22+ try {
23+ // Connect the client to the server
24+ await client . connect ( ) ;
25+
26+ // Establish and verify connection
27+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
28+ console . log ( "Connected successfully to server" ) ;
29+ } finally {
30+ // Ensures that the client will close when you finish/error
31+ await client . close ( ) ;
32+ }
33+ }
34+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change 1+ const { MongoClient } = require ( "mongodb" ) ;
2+
3+ // Connection URI
4+ const uri =
5+ "mongodb+srv://sample-hostname:27017/?poolSize=20&useUnifiedTopology=true" ;
6+
7+ // Create a new MongoClient
8+ const client = new MongoClient ( uri ) ;
9+
10+ async function run ( ) {
11+ try {
12+ // Connect the client to the server
13+ await client . connect ( ) ;
14+
15+ // Establish and verify connection
16+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
17+ console . log ( "Connected successfully to server" ) ;
18+ } finally {
19+ // Ensures that the client will close when you finish/error
20+ await client . close ( ) ;
21+ }
22+ }
23+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ Fundamentals
55.. default-domain:: mongodb
66
77.. toctree::
8- :caption: CRUD Operations
98
9+ /fundamentals/connection
1010 /fundamentals/crud
1111 /fundamentals/authentication
1212 /fundamentals/logging
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ Overview
1515These guides show you how to authenticate to a MongoDB instance using the
1616Node.js driver.
1717
18- The `Authentication Mechanisms <authentication-mechanisms>`_ guide contains
18+ The `Authentication Mechanisms <authentication/authentication -mechanisms>`_ guide contains
1919sample connection code using each authentication mechanism supported in the
2020MongoDB Community Edition which includes:
2121
@@ -26,7 +26,7 @@ MongoDB Community Edition which includes:
2626- ``X.509``
2727
2828The
29- `Enterprise Authentication Mechanisms <authentication-mechanisms-enterprise>`_
29+ `Enterprise Authentication Mechanisms <authentication/authentication -mechanisms-enterprise>`_
3030guide contains sample connection code using authentication mechanisms
3131available only in MongoDB Enterprise Edition which includes:
3232
Original file line number Diff line number Diff line change 22Enterprise Authentication Mechanisms
33====================================
44
5- In this section , you can find sample code for connection to MongoDB with each
5+ In this guide , you can find sample code for connection to MongoDB with each
66authentication mechanism available in the MongoDB Enterprise Edition:
77``Kerberos (GSSAPI/SSPI)`` and ``LDAP (PLAIN)``.
88
You can’t perform that action at this time.
0 commit comments