File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed
code-snippets/authentication
fundamentals/authentication Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -7,24 +7,26 @@ const clusterUrl = "<MongoDB cluster url>";
7
7
8
8
const authMechanism = "MONGODB-AWS" ;
9
9
10
- // Replace the following with your MongoDB deployment's connection string.
11
- const uri =
10
+ let uri =
12
11
`mongodb+srv://${ accessKeyId } :${ secretAccessKey } @${ clusterUrl } /?authMechanism=${ authMechanism } ` ;
13
12
14
- // Create a new MongoClient
13
+ // Uncomment the following lines if your AWS authentication setup requires a session token.
14
+ // const sessionToken = encodeURIComponent("<AWS_SESSION_TOKEN>");
15
+ // uri = uri.concat(`&authMechanismProperties=${sessionToken}`);
16
+
17
+ // Create a new MongoClient.
15
18
const client = new MongoClient ( uri ) ;
16
19
17
- // Function to connect to the server
18
20
async function run ( ) {
19
21
try {
20
- // Connect the client to the server
22
+ // Connect the client to the server.
21
23
await client . connect ( ) ;
22
24
23
- // Establish and verify connection
25
+ // Establish and verify connection.
24
26
await client . db ( "admin" ) . command ( { ping : 1 } ) ;
25
- console . log ( "Connected successfully to server" ) ;
27
+ console . log ( "Connected successfully to server. " ) ;
26
28
} finally {
27
- // Ensures that the client will close when you finish/error
29
+ // Ensure that the client closes when it finishes/errors.
28
30
await client . close ( ) ;
29
31
}
30
32
}
Original file line number Diff line number Diff line change @@ -149,20 +149,19 @@ The driver checks the following sources for your credentials in order:
149
149
4. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
150
150
<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_.
151
151
152
- If you do not already have the `aws signature library <https://www.npmjs.com/package/aws4>`__,
152
+ If you do not already have the `AWS signature library <https://www.npmjs.com/package/aws4>`__,
153
153
install it using the following ``npm`` command:
154
154
155
155
.. code-block:: console
156
156
157
157
npm install aws4
158
158
159
159
The following code shows an example of specifying the ``MONGODB-AWS``
160
- authentication mechanism and credentials in the connection string.
160
+ authentication mechanism and credentials in the connection string:
161
161
162
162
.. literalinclude:: /code-snippets/authentication/aws.js
163
163
:language: javascript
164
164
165
-
166
165
``X.509``
167
166
---------
168
167
You can’t perform that action at this time.
0 commit comments