Skip to content

Instantly share code, notes, and snippets.

@AkshayCHD
Created January 12, 2022 04:01
Show Gist options
  • Save AkshayCHD/a4bbaa0e89243ff852b9b02510df0fc1 to your computer and use it in GitHub Desktop.
Save AkshayCHD/a4bbaa0e89243ff852b9b02510df0fc1 to your computer and use it in GitHub Desktop.
const mongoose = require("mongoose");
const username = "root";
const password = "example";
const dbname = "mongo-sinon";
mongoose.connect(
`mongodb://${username}:${password}@localhost:27017/${dbname}?authSource=admin&readPreference=primary`,
{
useNewUrlParser: true,
useUnifiedTopology: true,
}
);
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error: "));
db.once("open", async function () {
console.log("Connected successfully");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment