Skip to content

Instantly share code, notes, and snippets.

@shalvah
Created February 14, 2018 08:03
Show Gist options
  • Save shalvah/83c848a49f10bf02e64e7f981c5516c2 to your computer and use it in GitHub Desktop.
Save shalvah/83c848a49f10bf02e64e7f981c5516c2 to your computer and use it in GitHub Desktop.
Twitter-Realtime-Likes
#!/usr/bin/env node
let faker = require('faker');
let Post = require('../models/post');
// connect to MongoDB
require('mongoose').connect('mongodb://localhost/poster');
// remove all data from the collection first
Post.remove({})
.then(() => {
let posts = [];
for (let i = 0; i < 30; i++) {
posts.push({
text: faker.lorem.sentence(),
posted_at: faker.date.past(),
likes_count: Math.round(Math.random() * 20),
author: faker.name.findName()
});
}
return Post.create(posts);
}).then(() => {
process.exit();
}).catch((e) => {
console.log(e);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment