Created
October 26, 2022 04:36
-
-
Save Deeks900/e7f81d07cd5bf73927210ae71f73d8cc to your computer and use it in GitHub Desktop.
mongo.js
This file contains hidden or 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
const { MongoClient } = require("mongodb"); | |
const uri = "mongodb://localhost:27017/Bookstore" | |
let dbConnection; | |
const getDb = ()=>dbConnection | |
const connectToDb = async(cb)=>{ | |
MongoClient.connect(uri) | |
.then((client)=>{ | |
dbConnection = client.db() | |
console.log("Connection Successful") | |
return cb(); | |
}) | |
.catch(err=>{ | |
console.log(err); | |
return cb(err); | |
}) | |
}; | |
module.exports = { | |
connectToDb, | |
getDb | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment