-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoose.js
101 lines (85 loc) · 2.33 KB
/
mongoose.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require('dotenv-extended').load({
encoding: 'utf8',
silent: true,
path: '.env',
defaults: '.env.defaults',
schema: '.env.schema',
errorOnMissing: false,
errorOnExtra: false,
includeProcessEnv: false,
assignToProcessEnv: true,
overrideProcessEnv: false
});
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('MongoDB connected successfully'))
.catch(err => console.error('MongoDB connection error:', err));
//-------------------------------------------------------------------------------------------------------------------
const ticketsSchema = new mongoose.Schema(
{
ticketNumber: Number,
name: String,
phoneNumber: String,
email: String,
description: String,
logs: String,
status: {
type: String,
default: 'Open'
},
createdAt: String,
updatedAt: String
},
{
versionKey: false
}
);
const Tickets = mongoose.model('Tickets', ticketsSchema);
const DUMMY_TICKET = {
ticketNumber: '100001',
name: 'Laxus',
phoneNumber: '+62 349 28349',
email: '[email protected]',
description: 'Unable to access my account',
logs: "I can't sign in to my account since this morning",
createdAt: '03:03:48 16/09/2018',
updatedAt: '03:03:48 16/09/2018'
};
Tickets.insertMany(DUMMY_TICKET).then(result => console.log(result));
//-------------------------------------------------------------------------------------------------------------------
const counterSchema = new mongoose.Schema(
{
name: String,
ticketNumber: Number
},
{
versionKey: false
}
);
const Counter = mongoose.model('Counters', counterSchema);
const DUMMY_COUNTER = {
name: 'ticketNumber',
ticketNumber: 100001
};
Counter.insertMany(DUMMY_COUNTER).then(result => console.log(result));
//-------------------------------------------------------------------------------------------------------------------
const logsSchema = new mongoose.Schema(
{
ticketNumber: Number,
logs: String,
updatedAt: String
},
{
versionKey: false
}
);
const Logs = mongoose.model('Logs', logsSchema);
const DUMMY_LOGS = {
ticketNumber: 100001,
logs: "Checking the issue...",
updatedAt: "07:03:48 16/09/2018"
};
Logs.insertMany(DUMMY_LOGS).then(result => console.log(result));