-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
58 lines (50 loc) · 2.23 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: "Wolfgang Mozart",
image: "https://www.biography.com/.image/t_share/MTE1ODA0OTcxNzMyNjY1ODY5/wolfgang-mozart-9417115-2-402.jpg",
description: "A prolific artist, Austrian composer Wolfgang Mozart created a string of operas, concertos, symphonies and sonatas that profoundly shaped classical music."
},
{
name: "Johann Sebastian Bach",
image: "https://www.biography.com/.image/t_share/MTIwNjA4NjMzNzMxNjQ2OTg4/johann-sebastian-bach-9194289-1-402.jpg",
description: "A magnificent baroque-era composer, Johann Sebastian Bach is revered through the ages for his work's musical complexities and stylistic innovations."
},
{
name: "Frederic Chopin",
image: "https://www.biography.com/.image/c_fill%2Ccs_srgb%2Cg_face%2Ch_300%2Cq_80%2Cw_300/MTE1ODA0OTcxNTg2OTc5MzQx/frederic-chopin-9247162-1-402.jpg",
description: "Considered Poland's greatest composer, Frédéric Chopin focused his efforts on piano composition and was a strong influence on composers who followed him."
}
];
function seedDB(){
//Remove all teachers
Teacher.remove({}, function(err){
console.log("removed Teachers!");
// add some Teachers
data.forEach(function(seed){
Teacher.create(seed, function(err, teacher){
if (err){
console.log(err);
} else{
console.log("added a Teacher");
Comment.create(
{
text: "Great teacher, just as expected!",
author: "Homer"
}, function(err, comment){
if (err){
console.log(err);
} else{
teacher.comments.push(comment);
teacher.save();
console.log("created new Comment!")
};
});
};
});
});
});
};
module.exports = seedDB;