File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11MONGO_URI = " mongodb+srv://rjReactDev:Deadrjs%407@cluster0.as2wbdp.mongodb.net/?retryWrites=true&w=majority"
2- PORT = 3033
2+ PORT = 3033
3+ # local db url should be replaced
4+ # MONGO_URI='mongodb://localhost/nodeapi'
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ const uri = "mongodb+srv://rjReactDev:90QcwhEs8LNtwy7L@cluster0.as2wbdp.mongodb.
1818
1919const client = new MongoClient ( uri , {
2020 useUnifiedTopology : true ,
21+ useNewUrlParser : true ,
2122 serverApi : {
2223 version : ServerApiVersion . v1 ,
2324 strict : true ,
@@ -29,15 +30,24 @@ async function run() {
2930 // Connect the client to the server (optional starting in v4.7)
3031 await client . connect ( ) ;
3132 // Send a ping to confirm a successful connection
32- // await client.db("admin").command({ ping: 1 });
33+ await client . db ( "admin" ) . command ( { ping : 1 } ) ;
3334 console . log ( "Pinged your deployment. You successfully connected to MongoDB!" ) ;
35+ await listDatabases ( client ) ;
3436 } finally {
3537 // Ensures that the client will close when you finish/error
3638 await client . close ( ) ;
3739 }
3840}
3941run ( ) . catch ( console . dir ) ;
4042
43+ //get all database list
44+ async function listDatabases ( client ) {
45+ databasesList = await client . db ( ) . admin ( ) . listDatabases ( ) ;
46+
47+ console . log ( "Databases:" ) ;
48+ databasesList . databases . forEach ( db => console . log ( ` - ${ db . name } ` ) ) ;
49+ } ;
50+
4151//const postRoutes =require('./routes/post')
4252
4353//using destructuring method
You can’t perform that action at this time.
0 commit comments