Guest User

server(main.js)

a guest
Nov 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Meteor } from 'meteor/meteor';
  2. import { Products} from '../imports/collections/products';
  3. import _ from 'lodash';
  4. import {image,commerce} from 'faker';
  5.  
  6. Meteor.startup(() => {
  7.   // code to run on server at startup
  8.   const numberRecords=Products.find({}).count();
  9.   console.log(numberRecords);
  10.  
  11.   if(!numberRecords){
  12.     _.times(72,()=>{
  13.     const productName=commerce.productName();
  14.     const price=commerce.price();
  15.     const productImage=image.food();
  16.     const section=_.random(1,3);
  17.     const category=_.random(1,4);
  18.     Products.insert({productName,price,section,category,productImage:image.food()});
  19.   });
  20.   }
  21.  
  22.  
  23.   Meteor.publish('products',function(PER_PAGE){
  24.     return (Products.find({},{limit:PER_PAGE}));
  25.   });
  26.  
  27.  
  28.    
  29. });
Add Comment
Please, Sign In to add comment