File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
test/integration/node-specific/examples Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change 2
2
const { MongoClient } = require ( 'mongodb' ) ;
3
3
4
4
// 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()
14
7
// 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
+ } ) ;
16
16
17
17
module . exports . handler = async function ( ) {
18
18
const databases = await client . db ( 'admin' ) . command ( { listDatabases : 1 } ) ;
You can’t perform that action at this time.
0 commit comments