-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
69 lines (62 loc) · 3.32 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
63
64
65
66
67
68
69
var mongoose = require("mongoose");
var campground = require("./models/campgrounds");
var comment = require("./models/comments");
var data = [
{
location:"Ohio",
image:"https://images.unsplash.com/photo-1515408320194-59643816c5b2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
desc:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur purus at enim dapibus hendrerit et in mauris. Nam tellus sem, varius sed facilisis sit amet, egestas nec justo. Nunc venenatis iaculis turpis, vel aliquam arcu suscipit a. Curabitur eget aliquam mi. Donec auctor luctus pharetra. Ut neque sapien, vulputate vitae tortor eget, convallis feugiat tellus. Cras metus augue, suscipit nec augue quis, varius interdum felis. Quisque auctor urna et scelerisque vehicula. Nunc vel egestas nulla, sed dignissim quam. Fusce condimentum ornare felis non porttitor."
},
{
location:"Whiteacre",
image:"https://images.unsplash.com/photo-1533575770077-052fa2c609fc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
desc:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur purus at enim dapibus hendrerit et in mauris. Nam tellus sem, varius sed facilisis sit amet, egestas nec justo. Nunc venenatis iaculis turpis, vel aliquam arcu suscipit a. Curabitur eget aliquam mi. Donec auctor luctus pharetra. Ut neque sapien, vulputate vitae tortor eget, convallis feugiat tellus. Cras metus augue, suscipit nec augue quis, varius interdum felis. Quisque auctor urna et scelerisque vehicula. Nunc vel egestas nulla, sed dignissim quam. Fusce condimentum ornare felis non porttitor."
},
{
location:"Arizona",
image:"https://images.unsplash.com/photo-1517398658731-17b18f07b5dc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
desc:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur purus at enim dapibus hendrerit et in mauris. Nam tellus sem, varius sed facilisis sit amet, egestas nec justo. Nunc venenatis iaculis turpis, vel aliquam arcu suscipit a. Curabitur eget aliquam mi. Donec auctor luctus pharetra. Ut neque sapien, vulputate vitae tortor eget, convallis feugiat tellus. Cras metus augue, suscipit nec augue quis, varius interdum felis. Quisque auctor urna et scelerisque vehicula. Nunc vel egestas nulla, sed dignissim quam. Fusce condimentum ornare felis non porttitor."
}
]
function seedDB()
{
comment.deleteMany({},function(err){
if(err)
console.log(err);
else{
console.log("removed comments");
campground.deleteMany({},function(err){//model.remove() is a deprecated method now
if(err)
console.log(err);
else
{
console.log("removed campgrounds");
data.forEach(function(seed){//we keep this inside the callback intentionally
campground.create(seed,function(err,adcamp){
if(err)
console.log(err);
else
{
console.log("campground created");
comment.create({
content:"This is a very nice place and I am thrilled to be here",
author:"Young Dumb"
},function(err,com){
if(err)
console.log(err);
else
{
console.log("comment created");
adcamp.comments.push(com);
adcamp.save();
}
});
}
});
});
}
});
}
});
}
module.exports = seedDB;