-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
87 lines (72 loc) · 1.57 KB
/
seed.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
const dotenv = require('dotenv');
dotenv.config({
silent: true
});
const {
PROD_URL,
DEV_URL,
} = process.env;
var mongoose = require('mongoose');
// Connect to MongoDB and create/use database called fcteste
mongoose.connect(DEV_URL);
// Create a schema
var ProductSchema = new mongoose.Schema({
name: String,
price: Number,
category: String
});
// Create a model based on the schema
var Product = mongoose.model('Product', ProductSchema);
const logDoc = (err, todo) => {
if (err) console.log(err);
else console.log('Product', todo.name,'created.');
}
console.log('\n\Seeding test db');
(async() => {
await Product.create({
name: "Martelo",
price: 10,
category: "Ferramentas"
}, logDoc);
await Product.create({
name: "Maçarico",
price: 375,
category: "Ferramentas"
}, logDoc);
await Product.create({
name: "Chave de Fenda",
price: 12,
category: "Ferramentas"
}, logDoc);
await Product.create({
name: "Celular",
price: 999.99,
category: "Eletrônicos"
}, logDoc);
await Product.create({
name: "Notebook",
price: 2000,
category: "Eletrônicos"
}, logDoc);
await Product.create({
name: "TV",
price: 3500,
category: "Eletrônicos"
}, logDoc);
await Product.create({
name: "Batedeira",
price: 190,
category: "Utensílios"
}, logDoc);
await Product.create({
name: "Liquidificador",
price: 99,
category: "Utensílios"
}, logDoc);
await Product.create({
name: "Fogão",
price: 500,
category: "Utensílios"
}, logDoc);
process.exit()
})()