-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
42 lines (37 loc) · 988 Bytes
/
db.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
31
32
33
34
35
36
37
38
39
40
41
42
// Importing mongoose library
const mongoose = require('mongoose');
// Connecting to MongoDB Atlas database
mongoose
.connect(
'mongodb+srv://lync:[email protected]/',
{ useNewUrlParser: true, useUnifiedTopology: true } // Adding options object
)
.then(() => {
console.log('Connected to MongoDB Atlas');
})
.catch((error) => {
console.error('Error connecting to MongoDB Atlas:', error);
});
// Defining schema for component collection
const componentSchema = new mongoose.Schema({
componentId: String,
data: { type: String, required: true },
});
// Defining schema for count collection
const countSchema = new mongoose.Schema({
addCount: {
type: Number,
default: 0,
},
updateCount: {
type: Number,
default: 0,
},
});
const ComponentDb = mongoose.model('ComponentDb', componentSchema);
const CountDb = mongoose.model('CountDb', countSchema);
// Exporting models
module.exports = {
ComponentDb,
CountDb,
};