-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
26 lines (22 loc) · 645 Bytes
/
db.js
File metadata and controls
26 lines (22 loc) · 645 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
const mongoose = require('mongoose');
require('dotenv').config();
const messageSchema = new mongoose.Schema({
sender: String,
receiver: String,
body: String,
type: String,
mimeType: String,
url: String,
timestamp: { type: Date, default: Date.now }
})
const Message = mongoose.model('Message', messageSchema);
const connectToDatabase = async () => {
try {
await mongoose.connect(process.env.MONGO_URL);
console.log('MongoDb connected successfully');
}
catch (error) {
console.log('Error connecting to database', error);
}
};
module.exports = { connectToDatabase, Message };