Skip to content

Commit

Permalink
Merge pull request #3 from RjSingh1529/dev
Browse files Browse the repository at this point in the history
added databaselist code
  • Loading branch information
ReactWithRajesh authored Sep 11, 2023
2 parents 3d35317 + b189995 commit 871b780
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
MONGO_URI="mongodb+srv://rjReactDev:Deadrjs%[email protected]/?retryWrites=true&w=majority"
PORT=3033
PORT=3033
# local db url should be replaced
# MONGO_URI='mongodb://localhost/nodeapi'
12 changes: 11 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const uri = "mongodb+srv://rjReactDev:[email protected].

const client = new MongoClient(uri, {
useUnifiedTopology: true,
useNewUrlParser: true,
serverApi: {
version: ServerApiVersion.v1,
strict: true,
Expand All @@ -29,15 +30,24 @@ async function run() {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Send a ping to confirm a successful connection
// await client.db("admin").command({ ping: 1 });
await client.db("admin").command({ ping: 1 });
console.log("Pinged your deployment. You successfully connected to MongoDB!");
await listDatabases(client);
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);

//get all database list
async function listDatabases(client) {
databasesList = await client.db().admin().listDatabases();

console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};

//const postRoutes =require('./routes/post')

//using destructuring method
Expand Down

0 comments on commit 871b780

Please sign in to comment.