Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #!/usr/bin/env node
  2.  
  3. let faker = require('faker');
  4. let Post = require('../models/post');
  5.  
  6. // connect to MongoDB
  7. require('mongoose').connect('mongodb://localhost/poster');
  8.  
  9. // remove all data from the collection first
  10. Post.remove({})
  11. .then(() => {
  12. let posts = [];
  13. for (let i = 0; i < 30; i++) {
  14. posts.push({
  15. text: faker.lorem.sentence(),
  16. posted_at: faker.date.past(),
  17. likes_count: Math.round(Math.random() * 20),
  18. author: faker.name.findName()
  19. });
  20. }
  21. return Post.create(posts);
  22. }).then(() => {
  23. process.exit();
  24. }).catch((e) => {
  25. console.log(e);
  26. process.exit(1);
  27. });
Add Comment
Please, Sign In to add comment