-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseeds.js
More file actions
53 lines (41 loc) · 971 Bytes
/
seeds.js
File metadata and controls
53 lines (41 loc) · 971 Bytes
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
var mongoose = require("mongoose"),
Campground = require("./models/campground");
Comment = require("./models/comment");
var data = [];
for(var i = 0; i < 2; i++){
data.push({
name: "Cloud's Rest",
image: "https://farm9.staticflickr.com/8002/7299820870_e78782c078.jpg",
description: " Good Camp you can have"
});
}
function seedDB(){
Campground.remove({},function(err){
if(err){
console.log(err);
}else{
console.log("Campground removed");
data.forEach(function(seed){
Campground.create(seed, function(err,data){
if(err){
console.log(err);
}else{
console.log("campground created");
Comment.create({text: "This place is great",
author: "Rishwanth"
},function(err,comment){
if(err){
console.log(err);
}else{
console.log("comment created");
data.comments.push(comment);
data.save();
}
});
}
});
});
}
});
}
module.exports = seedDB;