-
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
Showing
1 changed file
with
9 additions
and
9 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,15 +1,15 @@ | ||
const { config } = require("dotenv"); | ||
const mongoose = require("mongoose"); | ||
require("dotenv").config(); // this reads the .env file and sets the environment variables. | ||
const mongoose = require("mongoose"); // this is the ODM for MongoDB | ||
|
||
mongoose | ||
.connect( | ||
mongoose // this connects to the MongoDB database | ||
.connect( // the connection string is stored in the .env file | ||
"mongodb+srv://" + | ||
process.env.DB_USER_PASS + | ||
"@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", | ||
"@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", // this is the connection string | ||
{ | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
useNewUrlParser: true, // these are some options to avoid deprecation warnings | ||
useUnifiedTopology: true, // these are some options to avoid deprecation warnings | ||
} | ||
) | ||
.then(() => console.log("connected to MongoDB")) | ||
.catch((err) => console.log("Failed to connect to MongoDB :", err)); | ||
.then(() => console.log("connected to MongoDB")) // if the connection is successful, this message is printed | ||
.catch((err) => console.log("Failed to connect to MongoDB :", err)); // if the connection fails, this message is printed |