To seed the database, we'll pull the events we used earlier. We'll loop over them using an ES6 for...of loop.

Grab the events and loop over them to save using mongoose.

 * Seed the database
function seedEvents(req, res) {
  // create some events
  const events = [
    { name: 'Basketball', description: 'Throwing into a basket.' },
    { name: 'Swimming', description: 'Michael Phelps is the fast fish.' },
    { name: 'Weightlifting', description: 'Lifting heavy things up' },
    { name: 'Ping Pong', description: 'Super fast paddles' }

  // use the Event model to insert/save
  for (event of events) {
    var newEvent = new Event(event);;

  // seeded!
  res.send('Database seeded!');

Chris Sevilleja

167 posts

Co-founder of Slapping the keyboard until something good happens.