-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
57 lines (55 loc) · 1.6 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
var Campground = require("./models/campground")
mongoose = require("mongoose")
Comment = require("./models/comment");
var data=[
{
name:"Vandusen Garden",
image:"https://i.ytimg.com/vi/sGl3PwLtBHo/maxresdefault.jpg",
description:"Fall color in Vancouver #1"
},
{
name:"Fall Foliage in Vancouver",
image:"https://www.tripsavvy.com/thmb/sHtb8LHMz6ApkqmAyfe4oIY0GRc=/2121x1414/filters:fill(auto,1)/GettyImages-157506090-62713930973f496aa410b7833e3e2744.jpg",
description:"Best place"
},
{
name:"Winnipeg’s Kildonan Park",
image:"https://traveler.marriott.com/wp-content/uploads/2017/09/GI_647676896_FallLeaves_Water.jpg",
description:"For vibrant shades, trek along the Red and Assiniboine Rivers to take in fall’s best offerings. And don’t forget the fantastic plantings and towering trees at Assiniboine Park, one of the top urban parks in North America"
}
]
function seedDB(){
//Remove All Campgrounds
Campground.deleteOne({},function(err){
if(err){
console.log(err);
}
console.log("removed campgrounds!");
//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");
Comment.create(
{
text:"This is a very nice place, just needs internet",
author:"user"
},
function(err,comment){
if(err){
console.log(err);
}else{
campground.comments.push(comment);
campground.save();
console.log("added new comment");
}
});
}
});
});
});
}
module.exports=seedDB;