Need help with meteor-factory?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

108 Stars 20 Forks MIT License 74 Commits 14 Opened issues


Meteor package for creating test data or generating fixtures

Services available


Need anything else?

Contributors list

Meteor Factory

A package for creating test data or for generating fixtures.


$ meteor add dburles:factory

Table of Contents


Defining factories

Authors = new Meteor.Collection('authors');
Books = new Meteor.Collection('books');

Factory.define('author', Authors, { name: 'John Smith' }).after(author => { // Do something smart });

Factory.define('book', Books, { authorId: Factory.get('author'), name: 'A book', year() { return _.random(1900, 2014); } });

// We can also extend from an existing factory Factory.define('anotherBook', Books, Factory.extend('book', { // ... }));

Creating documents

// Ex. 1: Inserts a new book into the books collection
const book = Factory.create('book');

// Ex. 2: New fields can be added or overwritten const book = Factory.create('book', { name: 'A better book' });


Note: When calling

both the Book and an Author are created. The newly created Author
will then be automatically assigned to that field. In the case of calling'book')
as no insert operations are run, the
will be faked.


Factory.define('name', Collection, doc).after(doc => { ... })
  • name
    • A name for this factory
  • Collection
    • A meteor collection
  • doc
    • Document object
  • .after hook (Optional)
    • Returns the newly inserted document after calling



Returns the instance of name. Typical usage is to specify a relationship between collections as seen in the Book example above.

build'name', doc)

Builds the data structure for this factory

  • name
    • The name defined for this factory
  • doc (Optional)
    • Document object


Factory.tree('name', doc)

Builds an object tree without

fields. Useful for generating data for templates.
  • name
    • The name define for this factory
  • doc (Optional)
    • Document object


  Factory.define('author', Authors, {
    name: "John Smith"

Factory.define('book', Books, { name: "A book", author: Factory.get('author') });

const book = Factory.tree('book');

then equals:
  name: 'A book',
  author: {
    name: 'John Smith'


Factory.create('name', doc)

Creates (inserts) this factory into mongodb

  • name
    • The name defined for this factory
  • doc (Optional)
    • Document object


Factory.extend('name', doc)

Extend from an existing factory

  • name
    • The name defined for this factory
  • doc (Optional)
    • Document object


Fake makes a great companion package. See


MIT. (c) Percolate Studio

factory was developed as part of the Verso project.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.