-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
59 lines (55 loc) · 2.81 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
var mongoose = require("mongoose");
var Campground = require("./models/campgrounds");
var Comment = require("./models/comment");
var data = [
{
name: "Cloud's Rest",
image: "https://pixabay.com/get/53e4d1424b56a814f1dc84609620367d1c3ed9e04e507748752a7ed0904cc4_340.jpg",
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nisl eros, pulvinar facilisis justo mollis, auctor consequat urna. Morbi a bibendum metus. Donec scelerisque sollicitudin enim eu venenatis. Duis tincidunt laoreet ex, in pretium orci vestibulum eget. aptent taciti sociosqu ad litora torquent",
},
{
name: "Borkoom Campgrounds",
image: "https://pixabay.com/get/52e8d4444255ae14f1dc84609620367d1c3ed9e04e507748752a7ed0904cc4_340.jpg",
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nisl eros, pulvinar facilisis justo mollis, auctor consequat urna. Morbi a bibendum metus. Donec scelerisque sollicitudin enim eu venenatis. Duis tincidunt laoreet ex, in pretium orci vestibulum eget. aptent taciti sociosqu ad litora torquent"
},
{
name: "VInewood Hills",
image: "https://pixabay.com/get/53e2dc4b4d54a514f1dc84609620367d1c3ed9e04e507748752a73d39244c4_340.jpg",
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nisl eros, pulvinar facilisis justo mollis, auctor consequat urna. Morbi a bibendum metus. Donec scelerisque sollicitudin enim eu venenatis. Duis tincidunt laoreet ex, in pretium orci vestibulum eget. aptent taciti sociosqu ad litora torquent"
}
]
function seedDB(){
//Remove all campgrounds
Campground.deleteMany({}, 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");
//create a comment
Comment.create(
{
text: "This place is great but I wish there was internet",
author: "Homer"
}, function(err, comment){
if(err){
console.log(err);
} else {
campground.comments.push(comment._id);
campground.save();
console.log("Created new comment");
}
});
}
});
});
});
//add a few comments
}
module.exports = seedDB;