-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
executable file
·58 lines (55 loc) · 1.77 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
var mongoose = require("mongoose");
var Teacher = require("./models/teacher");
var Comment = require("./models/comment");
var data = [
{
name: "Joe Teacher",
image: "http://hotemoji.com/images/emoji/0/1nhll4o1aczf50.png",
description: "Best Teacher Ever!"
},
{
name: "Jim Teacher",
image: "http://hotemoji.com/images/emoji/0/1nhll4o1aczf50.png",
description: "Great Instructor!"
},
{
name: "Jack Teacher",
image: "http://hotemoji.com/images/emoji/0/1nhll4o1aczf50.png",
description: "Lacked Enthusiasm for the Subject"
}
]
function seedDB(){
//Remove all teachers
Teacher.remove({}, function(err){
if(err){
console.log(err);
}
console.log("removed teachers!");
//add a few teachers
data.forEach(function(seed){
Teacher.create(seed, function(err, teacher){
if(err){
console.log(err)
} else {
console.log("added a teacher");
//create a comment
Comment.create(
{
text: "this teacher and class are very interesting",
author: "Katie"
}, function(err, comment){
if(err){
console.log(err);
} else {
teacher.comments.push(comment);
teacher.save();
console.log("Created new comment");
}
});
}
});
});
});
//add a few comments
}
module.exports = seedDB;