-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
27 lines (19 loc) · 684 Bytes
/
db.js
File metadata and controls
27 lines (19 loc) · 684 Bytes
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
const mongoose = require("mongoose");
const dbString = "";
mongoose.connect(dbString,{ useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
// we're connected!
console.log('Connection to database open')
});
db.on('connected', function () {
console.log('Connection to database connected!');
});
db.on('reconnected', function () {
console.log('Database reconnected!');
});
db.on('disconnected', function () {
console.log('Disconnected trying to reconnect')
mongoose.connect(dbString, { useNewUrlParser: true, useUnifiedTopology: true })
})