-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeds.js
More file actions
104 lines (95 loc) · 3.41 KB
/
seeds.js
File metadata and controls
104 lines (95 loc) · 3.41 KB
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
const mongoose = require("mongoose"),
Campground = require("./models/campground"),
Comment = require("./models/comment"),
data = [
{
name: "rainbow lakes",
image:"https://source.unsplash.com/700x390/?forest,pond,lake",
cost: 0.00,
location: "right here",
description: "lots of sun, no privacy",
author: {
username: "SallyRideOrDie"
}
},
{
name: "badger hollow",
image:"https://source.unsplash.com/700x390/?trees,thicket,field",
cost: 0.00,
location: "over there",
description: "lots of privacy, no sun",
author: {
username: "Warren2020"
}
},
{
name: "menagerie coast",
image:"https://source.unsplash.com/700x390/?trees,coast,ocean",
cost: 0.00,
location: "north of fort collins",
description: "noisy and crowded",
},
{
name: "slayers take",
image:"https://source.unsplash.com/700x390/?woods,camping,mountain",
cost: 0.00,
location: "down",
description: "damp and misty, very private",
},
{
name: "nicodranas",
image:"https://source.unsplash.com/700x390/?mountain,woods,forest",
cost: 0.00,
location: "170 past idaho springs",
description: "beautiful and remote, lots of critters",
},
{
name: "bill's canyon",
image:"https://source.unsplash.com/700x390/?canyon,desert",
cost: 0.00,
location: "up",
description: "very icy in the spring, bring lots of blankets",
},
{
name: "salmon creek",
image:"https://source.unsplash.com/700x390/?stream,creek,brook",
cost: 0.00,
location: "second star to the left",
description: "beautiful but beware bears",
}
]
function seedDB(){
//Remove all camprounds
Campground.remove({}, function(err){
if(err) {
console.log(err)
} else {
console.log("campgrounds removed")
//Wait til they're gone then add a few campgrounds
data.forEach(function(seed){
Campground.create(seed, function(err, campground){
if(err) {
console.log(err)
} else {
console.log("added a campground")
//Add a few comments
Comment.create(
{
text: "great views, no internet",
author: "Ishmael"
}, function(err, comment){
if(err) {
console.log(err)
} else {
campground.comments.push(comment);
campground.save()
console.log("added new comment")
}
})
}
})
})
}
})
}
module.exports = seedDB;