-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
25 lines (20 loc) · 695 Bytes
/
Copy pathtest.js
File metadata and controls
25 lines (20 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const {MongoClient} = require('mongodb');
async function main(){
const uri = "mongodb+srv://kk6915:RGWxxTHWmb7vAUgh@cluster0.azxgd.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
const client = new MongoClient(uri);
try {
await client.connect();
console.log("Connected to Database");
await listDatabases(client);
} catch(e){
console.error(e);
} finally {
await client.close();
}
}
main().catch(console.error);
async function listDatabases(client){
databasesList = await client.db().admin().listDatabases();
console.log("Databases");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};