-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
55 lines (53 loc) · 1.74 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
var mongoose = require("mongoose");
var Campground = require("./models/campground");
var comment = require("./models/comment");
var data = [
{
name: "Sils Maria",
image: "http://www.photosforclass.com/download/8524305204",
description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
},
{
name: "Creek Point",
image: "http://www.photosforclass.com/download/15989950903",
description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
},
{
name: "Midnight Howl",
image: "http://www.photosforclass.com/download/7842069486",
description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
]
function seedDB(){
//Remove all campgrounds
Campground.remove({},function(err){
if(err){
console.log(err);
} else
console.log("removed campgrounds!!!");
//add campgrounds
data.forEach(function(seed){
Campground.create(seed,function(err,campground){
if(err){
console.log(err);
} else {
console.log("Successfully added to the DB!");
}
//add comments
comment.create({
text:"This place must have internet!@",
author: "Homey"
},function(err,comment){
if(err){
console.log(err);
} else {
campground.comments.push(comment);
campground.save();
console.log("Created new comment Successfully");
}
});
});
});
});
};
module.exports = seedDB;