-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
53 lines (47 loc) · 1.43 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
const mongoose = require('mongoose');
const mongooseeder = require('mongooseeder');
const models = require('./models');
const { User, Show } = require('./models');
mongoose.Promise = require('bluebird');
const mongodbUrl = 'mongodb://localhost/hackathon_development';
mongooseeder.seed({
mongodbUrl: mongodbUrl,
models: models,
clean: true,
mongoose: mongoose,
seeds: () => {
let userSeeds = [];
const user = new User({
name: 'Tyrus',
shows: []
});
userSeeds.push(user);
let showSeeds = [];
const shows = [
{ title: 'Hey Duggee', image: 'images/duggee.jpg' },
{ title: 'Blaze and the Monster Machines', image: 'images/blaze.jpeg' },
{ title: 'Rusty Rivets', image: 'images/rusty.jpeg' },
{ title: 'Mickey Mouse Clubhouse', image: 'images/mickey.jpeg' },
{ title: 'Peppa Pig', image: 'images/peppa.jpeg' },
{ title: 'The Wiggles', image: 'images/wiggles.jpeg' }
];
for (let i = 0; i < shows.length; i++) {
show = new Show({
title: shows[i].title,
user: user._id,
image: shows[i].image
});
showSeeds.push(show);
user.shows.push(show._id);
}
const collections = [userSeeds, showSeeds];
const promises = [];
collections.forEach(collection => {
collection.forEach(model => {
const promise = model.save();
promises.push(promise);
});
});
return Promise.all(promises);
}
});