-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeder.js
44 lines (41 loc) · 928 Bytes
/
seeder.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
/** @format */
const mongoose = require('mongoose');
const colors = require('colors');
const dotenv = require('dotenv');
//env
dotenv.config({ path: './config/config.env' });
const User = require('./models/User');
const Lobby = require('./models/Lobby');
//Connect
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
//Import into DB
const importData = async () => {
try {
await User.create(users);
console.log('Data Imported...'.green.inverse);
process.exit();
} catch (err) {
console.log(err);
}
};
//Delete data
const deleteData = async () => {
try {
await User.deleteMany();
await Lobby.deleteMany();
console.log('Data destroy...'.red.inverse);
process.exit();
} catch (err) {
console.log(err);
}
};
if (process.argv[2] === '-i') {
importData();
} else if (process.argv[2] === '-d') {
deleteData();
}