Skip to content

Instantly share code, notes, and snippets.

@helfer
Created April 22, 2016 22:22
Show Gist options
  • Save helfer/284b27bf70786afb8cf196af3800386b to your computer and use it in GitHub Desktop.
Save helfer/284b27bf70786afb8cf196af3800386b to your computer and use it in GitHub Desktop.
// at the top with imports:
import Mongoose from 'mongoose';
// somewhere in the middle:
const mongo = Mongoose.connect('mongodb://localhost/views');
const ViewSchema = Mongoose.Schema({
postId: Number,
views: Number,
});
const View = Mongoose.model('views', ViewSchema);
// modify the mock data creation to also create some views:
casual.seed(123);
db.sync({ force: true }).then(() => {
_.times(10, () => {
return AuthorModel.create({
firstName: casual.first_name,
lastName: casual.last_name,
}).then((author) => {
return author.createPost({
title: `A post by ${author.firstName}`,
text: casual.sentences(3),
}).then((post) => { // <- the new part starts here
// create some View mocks
return View.update(
{ postId: post.id },
{ views: casual.integer(0, 100) },
{ upsert: true });
});
});
});
});
// at the bottom, add View to the exports
export { Author, Post, View };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment