-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydb.js
More file actions
38 lines (27 loc) · 1.06 KB
/
mydb.js
File metadata and controls
38 lines (27 loc) · 1.06 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
var MongoClient = require('mongodb').MongoClient;
async function main(){
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url> to reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = "mongodb+srv://process.env.username:process.env.password@resourcescluster.e3fwh.mongodb.net/?retryWrites=true&w=majority&appName=ResourcesCluster";
const client = new MongoClient(uri);
async function listDatabases(client){
var databasesList = await client.db().admin().listDatabases();
console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
console.log("\n");
console.log("Conexion successful");
};
try {
// Connect to the MongoDB cluster
await client.connect();
// Make the appropriate DB calls
await listDatabases(client);
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
main().catch(console.error);