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>";
77
88const authMechanism = "MONGODB-AWS" ;
99
10- // Replace the following with your MongoDB deployment's connection string.
11- const uri =
10+ let uri =
1211 `mongodb+srv://${ accessKeyId } :${ secretAccessKey } @${ clusterUrl } /?authMechanism=${ authMechanism } ` ;
1312
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.
1518const client = new MongoClient ( uri ) ;
1619
17- // Function to connect to the server
1820async function run ( ) {
1921 try {
20- // Connect the client to the server
22+ // Connect the client to the server.
2123 await client . connect ( ) ;
2224
23- // Establish and verify connection
25+ // Establish and verify connection.
2426 await client . db ( "admin" ) . command ( { ping : 1 } ) ;
25- console . log ( "Connected successfully to server" ) ;
27+ console . log ( "Connected successfully to server. " ) ;
2628 } finally {
27- // Ensures that the client will close when you finish/error
29+ // Ensure that the client closes when it finishes/errors.
2830 await client . close ( ) ;
2931 }
3032}
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:
1491494. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks
150150 <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_.
151151
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>`__,
153153install it using the following ``npm`` command:
154154
155155.. code-block:: console
156156
157157 npm install aws4
158158
159159The 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:
161161
162162.. literalinclude:: /code-snippets/authentication/aws.js
163163 :language: javascript
164164
165-
166165``X.509``
167166---------
168167
You can’t perform that action at this time.
0 commit comments