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 1
1
name = " node"
2
- toc_landing_pages = [" /crud" , " /crud/read-operations" , " /crud/write-operations" ]
2
+ # toc_landing_pages = ["/crud", "/crud/read-operations", "/crud/write-operations"]
3
3
4
4
[constants ]
5
5
version = 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
5
5
.. default-domain:: mongodb
6
6
7
7
.. toctree::
8
- :caption: CRUD Operations
9
8
9
+ /fundamentals/connection
10
10
/fundamentals/crud
11
11
/fundamentals/authentication
12
12
/fundamentals/logging
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ Overview
15
15
These guides show you how to authenticate to a MongoDB instance using the
16
16
Node.js driver.
17
17
18
- The `Authentication Mechanisms <authentication-mechanisms>`_ guide contains
18
+ The `Authentication Mechanisms <authentication/authentication -mechanisms>`_ guide contains
19
19
sample connection code using each authentication mechanism supported in the
20
20
MongoDB Community Edition which includes:
21
21
@@ -26,7 +26,7 @@ MongoDB Community Edition which includes:
26
26
- ``X.509``
27
27
28
28
The
29
- `Enterprise Authentication Mechanisms <authentication-mechanisms-enterprise>`_
29
+ `Enterprise Authentication Mechanisms <authentication/authentication -mechanisms-enterprise>`_
30
30
guide contains sample connection code using authentication mechanisms
31
31
available only in MongoDB Enterprise Edition which includes:
32
32
Original file line number Diff line number Diff line change 2
2
Enterprise Authentication Mechanisms
3
3
====================================
4
4
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
6
6
authentication mechanism available in the MongoDB Enterprise Edition:
7
7
``Kerberos (GSSAPI/SSPI)`` and ``LDAP (PLAIN)``.
8
8
You can’t perform that action at this time.
0 commit comments