-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
182 lines (176 loc) · 4.61 KB
/
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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const mongoose = require('mongoose');
require('dotenv').config();
const userSchema = new mongoose.Schema({
username: String,
hash: String,
sign: String,
dob: Date,
createdAt: { type: Date, default: Date.now },
});
const signSchema = new mongoose.Schema({
name: String,
img: String,
});
mongoose.model('User', userSchema);
mongoose.model('Sign', signSchema);
function saveSignScript() {
const Sign = mongoose.model('Sign');
for (let i = 0; i < 12; i++) {
let sign = new Sign();
if (i === 0) {
sign.name = 'Aries';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_1-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Aries');
}
});
} else if (i === 1) {
sign.name = 'Taurus';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_2-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Taurus');
}
});
} else if (i === 2) {
sign.name = 'Gemini';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_9-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Gemini');
}
});
} else if (i === 3) {
sign.name = 'Cancer';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_4-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Cancer');
}
});
} else if (i === 4) {
sign.name = 'Leo';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_5-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Leo');
}
});
} else if (i === 5) {
sign.name = 'Virgo';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_6-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Virgo');
}
});
} else if (i === 6) {
sign.name = 'Libra';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_7-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Libra');
}
});
} else if (i === 7) {
sign.name = 'Scorpio';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_8-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Scorpio');
}
});
} else if (i === 8) {
sign.name = 'Sagittarius';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_12-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Sagittarius');
}
});
} else if (i === 9) {
sign.name = 'Capricorn';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_11-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Capricorn');
}
});
} else if (i === 10) {
sign.name = 'Aquarius';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_10-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Aquarius');
}
});
} else if (i === 11) {
sign.name = 'Pisces';
sign.img =
'https://cdn0.iconfinder.com/data/icons/zodiac-signs-14/100/Artboard_9-512.png';
sign.save((err) => {
if (err) {
console.log(err);
} else {
console.log('save Pisces');
}
});
}
}
}
mongoose.connect(
process.env.MongoURI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
},
(err) => {
if (err) {
console.log(err);
} else {
//trying to get collection names
mongoose.connection.db.listCollections().toArray(function (err, names) {
if (names.length === 1) {
saveSignScript();
} else if (!err) {
console.log('database connected');
}
});
}
},
);