-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rjss836
committed
Sep 11, 2023
1 parent
3d35317
commit b189995
Showing
2 changed files
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
|