-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
30 lines (26 loc) · 1 KB
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//The require(‘mongoose’) call above returns a Singleton object.
//It means that the first time you call require(‘mongoose’), it
//is creating an instance of the Mongoose class and returning it.
//On subsequent calls, it will return the same instance that was
//created and returned to you the first time because of how module
//import/export works in ES6.
const mongoose = require("mongoose");
mongoose.set('useNewUrlParser', true);
mongoose.set('useUnifiedTopology', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useUnifiedTopology', true);
class Database {
constructor() {
this.connect();
}
connect() {
mongoose.connect("mongodb+srv://Harsha:[email protected]/twitterclone?retryWrites=true&w=majority")
.then(() => {
console.log("database connection successful");
})
.catch((err) => {
console.log("database connection error " + err);
})
}
}
module.exports = new Database();