-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeds.js
More file actions
33 lines (22 loc) · 741 Bytes
/
seeds.js
File metadata and controls
33 lines (22 loc) · 741 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
28
29
30
31
32
33
const mongoose = require('mongoose');
const connectionURL = 'mongodb+srv://rifstudy7:B7Kdrz4TRPY3jpZz@cluster0.s7ccuri.mongodb.net/';
const databaseName = 'WebApplicationsProject';
mongoose.connect(connectionURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: databaseName
}).then(async () => {
console.log('Connected to the database');
}).catch((error) => {
console.log("Can't connect to the database:", error);
});
const db = mongoose.connection;
db.on('error', (error) => {
console.log("Database connection error:", error);
});
db.once('connected', () => {
console.log("Database connected successfully");
});
db.once('disconnected', () => {
console.log("Database disconnected");
});