Skip to content

Commit 1e4c1ae

Browse files
committed
test(NODE-4160): pass options to client
1 parent 30ecb53 commit 1e4c1ae

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/integration/node-specific/examples/aws_handler.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
const { MongoClient } = require('mongodb');
33

44
// Get the URI for the cluster then set AWS_ACCESS_KEY_ID as the username in the
5-
// URI and AWS_SECRET_ACCESS_KEY as the password, then set the appropriate
6-
// options.
7-
const connectionString = new URL(process.env.MONGODB_URI);
8-
connectionString.username = process.env.AWS_ACCESS_KEY_ID;
9-
connectionString.password = encodeURIComponent(process.env.AWS_SECRET_ACCESS_KEY);
10-
connectionString.searchParams.set('authSource', '$external');
11-
connectionString.searchParams.set('authMechanism', 'MONGODB-AWS');
12-
13-
// MongoClient now auto-connects so no need to store the connect()
5+
// URI and AWS_SECRET_ACCESS_KEY as the password, then set the appropriate auth
6+
// options. Note that MongoClient now auto-connects so no need to store the connect()
147
// promise anywhere and reference it.
15-
const client = new MongoClient(connectionString.toString());
8+
const client = new MongoClient(process.env.MONGODB_URI, {
9+
auth: {
10+
username: process.env.AWS_ACCESS_KEY_ID,
11+
password: encodeURIComponent(process.env.AWS_SECRET_ACCESS_KEY)
12+
},
13+
authSource: '$external',
14+
authMechanism: 'MONGODB-AWS'
15+
});
1616

1717
module.exports.handler = async function () {
1818
const databases = await client.db('admin').command({ listDatabases: 1 });

0 commit comments

Comments
 (0)