-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
61 lines (57 loc) · 1.19 KB
/
seeds.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
const mongoose = require("mongoose");
const Product = require("./models/product");
mongoose
.connect("mongodb://localhost:27017/farmStand2", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log(`Mongo connection open!!`);
})
.catch((err) => {
console.log("Mongo connection ERROR!!");
console.log(err);
});
// const p = new Product({
// name: "Pomegranate",
// price: 2,
// category: "Fruit",
// });
// p.save()
// .then((p) => {
// console.log(p);
// })
// .catch((err) => {
// console.log(err);
// });
//Instead of inserting one product like above we're gonna insert many of them in much quicker time:
const seedProducts = [
{
name: "Fairy Eggplanet",
price: 1.0,
category: "vegetable",
},
{
name: "organic Melon",
price: 4.19,
category: "fruit",
},
{ name: "organic Watermelon", price: 3.99, category: "fruit" },
{
name: "organic Celery",
price: 1.3,
category: "vegetable",
},
{
name: "coconut Milk",
price: 2.12,
category: "dairy",
},
];
Product.insertMany(seedProducts)
.then((p) => {
console.log(p);
})
.catch((err) => {
console.log(err);
});