-
Notifications
You must be signed in to change notification settings - Fork 2
/
seed.js
executable file
·62 lines (54 loc) · 1.96 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
var mongoose = require("mongoose"),
Campground = require("./models/campground"),
Comment = require("./models/comment")
var data = [
{
name: "Dragon ball",
image: "http://static.srcdn.com/slir/w700-h350-q90-c700:350/wp-content/uploads/Dragon-Ball-Super-Anime.jpg",
description: "yayayayyaya"
},
{
name: "8888888",
image: "http://static.srcdn.com/slir/w525-h262-q90-c525:262/wp-content/uploads/videos/1465421934616-brightcove0124-4797351740001-201606-3133-4797351740001_4931935980001_4931915391001-vs.jpg",
description: "uuuuuuuuu"
},
{
name: "Kylo-Ren",
image: "http://static.srcdn.com/slir/w525-h262-q90-c525:262/wp-content/uploads/LEGO-Star-Wars-Force-Awakens-trailer-Kylo-Ren.jpg",
description: "nonononononno"
}
]
function seedDB(){
// Remove all campgrounds
Campground.remove({}, function(err){
if (err) {
console.log(err)
} else {
console.log("remove campground!");
data.forEach(function(seed){
Campground.create(seed, function(err, campground){
if (err) {
console.log(err)
} else {
console.log("add a campground")
// creat a comment
Comment.create(
{
text: "wowowow",
author: "homer"
}, function(err, comment){
if (err) {
console.log(err)
} else {
campground.comments.push(comment);
campground.save();
console.log("creat new comment");
}
});
}
});
});
}
});
}
module.exports = seedDB;