-
Notifications
You must be signed in to change notification settings - Fork 3
/
seed.js
106 lines (100 loc) · 5.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var db = require("./models");
var newUsers = [
{
username: "NotNickLee"
},
{
username: "NotKenDong"
},
{
username: "NotBethWitten"
}];
var newCities = [
{name: "San Francisco"},
{name: "Boston"},
{name: "New York City"},
{name: "Seattle"},
{name: "Los Angeles"},
{name: "Austin"},
];
var newPosts = [
{
title: "Fog, fog city",
content: "Occupy raw denim lumbersexual marfa umami, poke whatever chia synth tbh. Slow-carb pork belly pickled single-origin coffee. Pug affogato farm-to-table retro put a bird on it thundercats, dreamcatcher drinking vinegar artisan man bun quinoa banh mi. Pop-up bespoke meggings photo booth, activated charcoal neutra aesthetic gluten-free sustainable cred sartorial four loko. Cronut small batch viral swag YOLO before they sold out shabby chic asymmetrical vice seitan godard readymade ugh franzen. Kinfolk poke chillwave neutra banjo flexitarian bespoke succulents hot chicken. Brooklyn iceland helvetica pickled try-hard wolf cold-pressed distillery sriracha freegan copper mug aesthetic.",
city: "San Francisco",
username: 'NotNickLee'
},
{
title: "Go Sox",
content: "Occupy raw denim lumbersexual marfa umami, poke whatever chia synth tbh. Slow-carb pork belly pickled single-origin coffee. Pug affogato farm-to-table retro put a bird on it thundercats, dreamcatcher drinking vinegar artisan man bun quinoa banh mi. Pop-up bespoke meggings photo booth, activated charcoal neutra aesthetic gluten-free sustainable cred sartorial four loko. Cronut small batch viral swag YOLO before they sold out shabby chic asymmetrical vice seitan godard readymade ugh franzen. Kinfolk poke chillwave neutra banjo flexitarian bespoke succulents hot chicken. Brooklyn iceland helvetica pickled try-hard wolf cold-pressed distillery sriracha freegan copper mug aesthetic.",
city: "Boston",
username: 'NotKenDong'
},
{
title: "Rain Rain and Microsoft",
content: "Occupy raw denim lumbersexual marfa umami, poke whatever chia synth tbh. Slow-carb pork belly pickled single-origin coffee. Pug affogato farm-to-table retro put a bird on it thundercats, dreamcatcher drinking vinegar artisan man bun quinoa banh mi. Pop-up bespoke meggings photo booth, activated charcoal neutra aesthetic gluten-free sustainable cred sartorial four loko. Cronut small batch viral swag YOLO before they sold out shabby chic asymmetrical vice seitan godard readymade ugh franzen. Kinfolk poke chillwave neutra banjo flexitarian bespoke succulents hot chicken. Brooklyn iceland helvetica pickled try-hard wolf cold-pressed distillery sriracha freegan copper mug aesthetic.",
city: "San Francisco",
username: 'NotBethWitten'
},
{
title: "It's not like other Texas",
content: "Occupy raw denim lumbersexual marfa umami, poke whatever chia synth tbh. Slow-carb pork belly pickled single-origin coffee. Pug affogato farm-to-table retro put a bird on it thundercats, dreamcatcher drinking vinegar artisan man bun quinoa banh mi. Pop-up bespoke meggings photo booth, activated charcoal neutra aesthetic gluten-free sustainable cred sartorial four loko. Cronut small batch viral swag YOLO before they sold out shabby chic asymmetrical vice seitan godard readymade ugh franzen. Kinfolk poke chillwave neutra banjo flexitarian bespoke succulents hot chicken. Brooklyn iceland helvetica pickled try-hard wolf cold-pressed distillery sriracha freegan copper mug aesthetic.",
city: "Austin",
username: 'NotNickLee'
},
{
title: "Drive...traffic traffic traffic...drive...traffic traffic traffic",
content: "Occupy raw denim lumbersexual marfa umami, poke whatever chia synth tbh. Slow-carb pork belly pickled single-origin coffee. Pug affogato farm-to-table retro put a bird on it thundercats, dreamcatcher drinking vinegar artisan man bun quinoa banh mi. Pop-up bespoke meggings photo booth, activated charcoal neutra aesthetic gluten-free sustainable cred sartorial four loko. Cronut small batch viral swag YOLO before they sold out shabby chic asymmetrical vice seitan godard readymade ugh franzen. Kinfolk poke chillwave neutra banjo flexitarian bespoke succulents hot chicken. Brooklyn iceland helvetica pickled try-hard wolf cold-pressed distillery sriracha freegan copper mug aesthetic.",
city: "Los Angeles",
username: 'NotNickLee'
}
];
db.User.remove({}, function(err, users){
db.User.create(newUsers, function(err, users){
// code in here runs after all albums are created
if (err) { return console.log('ERROR', err); }
console.log("all users:", users);
console.log("created", users.length, "users");
db.City.remove({}, function(err, users){
db.City.create(newCities, function(err, cities){
if(err) {return console.log('ERROR', err);}
console.log("all cities:", cities);
console.log('created', cities.length, 'cities');
db.Post.remove({}, function(err, posts){
console.log('removed all posts');
newPosts.forEach(function(postData) {
var post = new db.Post({
title: postData.title,
content: postData.content
});
db.User.findOne({username: postData.username}, function (err, foundUser) {
console.log(`found user ${foundUser.username} for for post ${post.title}`);
if (err) {
console.log(err);
return;
}
post._userId = foundUser._id;
console.log("\nUSER\N",foundUser._id)
db.City.findOne({name: postData.city}, function (err, foundCity) {
console.log(`found city ${foundCity.name} for for post ${post.title}`);
if (err) {
console.log(err);
return;
}
console.log("\City\n",foundCity._id)
post._cityId = foundCity._id;
post.save(function(err, savedPost){
if (err) {
return console.log(err);
}
console.log('saved post item');
process.exit(0);
});
});
});
});
});
})
})
})
})