-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
55 lines (51 loc) · 1.24 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
const mongoose= require("mongoose"),
Campground= require("./models/campground"),
Comment= require("./models/comment");
var data=[
{
name:"Coorg",
image:"http://blog.railyatri.in/wp-content/uploads/2018/06/Places-to-explore-in-Coorg.png",
description: "Coorg is an beautiful city situated in karnataka."
},
{
name:"Leh",
image:"https://img.traveltriangle.com/blog/wp-content/uploads/2018/04/acj-2404-camping-in-leh-5.jpg",
description: "Leh is one of the best mountain camping places in India."
},
{
name:"kerala Munnar",
image:"https://www.india.com/wp-content/uploads/2018/08/camp.jpg",
description:"God's own country"
}
];
function seedDB(){
Campground.deleteMany({},(err)=>{
if(err){
console.log(err);
}else{
console.log("removed campgrounds");
}
data.forEach(seed=>{
Campground.create(seed,(err,campground)=>{
if(err){
console.log(err);
}else{
console.log("added a campground");
Comment.create({
text:"This is an awesome place",
author:"George"
},(err,comment)=>{
if(err){
console.log(err);
}else{
campground.comments.push(comment);
campground.save();
console.log("Comment added");
}
});
}
});
});
});
}
module.exports=seedDB;