Advertisement
Adrian_Apostolov

Untitled

Jan 10th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose');
  2.  
  3. var missionSchema = mongoose.Schema({
  4.     award: {type: Number, require: '{PATH} is required'},
  5.     location: {type: String, require: '{PATH} is required'},
  6.     missionTarget: {type: String, require: '{PATH} is required'},
  7.     targetPicture : {type: String, require: '{PATH} is required'},
  8.     postedBy: {type: String, require: '{PATH} is required'},
  9.     difficult: {type: Number, require: '{PATH} is required'},
  10.     agent: {type: String},
  11.     description: {type: String}
  12. });
  13.  
  14. var Mission = mongoose.model('Mission', missionSchema);
  15.  
  16. module.exports.seedInitialMission = function() {
  17.     Mission.find({}).exec(function(err, collection) {
  18.         if (err) {
  19.             console.log('Cannot find missions: ' + err);
  20.             return;
  21.         }
  22.  
  23.         if (collection.length === 0) {
  24.  
  25.             Mission.create({
  26.                 award: 1000,
  27.                 location: 'Sofia',
  28.                 missionTarget: 'Big Nasty Politician',
  29.                 targetPicture : 'http://img.bg.sof.cmestatic.com/media/images/640x360/Apr2015/2110396926.jpg',
  30.                 postedBy: 'Pesho',
  31.                 difficult: 7,
  32.                 agent: 'Stamat',
  33.                 description: 'Some description'
  34.             });
  35.             Mission.create({
  36.                 award: 2000,
  37.                 location: 'Plovdiv',
  38.                 missionTarget: 'Crazy Mad Dictator',
  39.                 targetPicture: 'http://cache.reelz.com/assets/content/repFrame/62124/the-dictator-promo-01.jpg',
  40.                 postedBy: 'Stamat',
  41.                 difficult: 5,
  42.                 agent: 'Ivan',
  43.                 description: 'Some description'
  44.             });
  45.             Mission.create({
  46.                 award: 1500,
  47.                 location: 'Varna',
  48.                 missionTarget: 'The Wolf',
  49.                 targetPicture: 'http://unleashthewolf.com/images/wolf_slideshow01.jpg',
  50.                 postedBy: 'Gosho',
  51.                 difficult: 4,
  52.                 agent: 'Goshkata',
  53.                 description: 'Some description'
  54.             });
  55.  
  56.             console.log('Missions added to database...');
  57.         }
  58.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement