Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created November 29, 2020 04:20
Show Gist options
  • Save mirsahib/7a05c2d16835acbd245eccb9026ba3ad to your computer and use it in GitHub Desktop.
Save mirsahib/7a05c2d16835acbd245eccb9026ba3ad to your computer and use it in GitHub Desktop.
React_Serverless
import { MongoClient } from "mongodb";
function createClient() {
const client = new MongoClient(
`mongodb+srv://admin:${process.env.REACT_APP_DB_PASSWORD}@cluster0.si7bk.mongodb.net/test?retryWrites=true&w=majority`,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
(err) => {
if (err) console.log(err);
console.log("Database Connected");
}
);
client.usersCollection = function () {
return this.db("test").collection("users");
};
return client;
}
export { createClient };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment