-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
68 lines (60 loc) · 2.25 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
var mongoose = require("mongoose");
var Article = require("./models/article");
var Comment = require("./models/comment");
var data = [
{
name : "Cloud's Rest",
image: "https://farm4.staticflickr.com/3872/14435096036_39db8f04bc.jpg",
description : "tandard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only fi"
},
{
name : "Heaven's Moon",
image: "https://farm9.staticflickr.com/8422/7842069486_c61e4c6025.jpg",
description : "Your dreams will come true"
},
{
name : "The Horizon",
image: "https://farm9.staticflickr.com/8673/15989950903_8185ed97c3.jpg",
description : "Your horizon will exceed your excepctations"
},
];
function seedDB(){
// Remove all articles
Article.remove({},function(err){
if(err){
console.log(err);
} else{
// Add a few articles
addArticles();
console.log("Removed all articles");
}
});
// Add a few comments
}
function addArticles(){
data.forEach(function(seed){
Article.create(seed, function(err, article){
if(err){
console.log(err);
} else {
console.log("Added the article "+article);
// Create a comment
Comment.create(
{
text: "I want to go there!",
author: "John Petroch"
}, function(err, comment){
if(err){
console.log(err);
} else {
article.comments.push(comment);
article.save();
console.log("Created a new comment");
}
}
);
}
}) ;
});
}
module.exports = seedDB;