Automatically seed meteor collections with fake data using simple schema definition. ***Warning: *** It's a working in progress package and still does not support embedded schema so please feel free to submit pull request of bug reports for any issues you may come across.
To install, simply run the following command in the root of your meteor project -
meteor add foysalit:seeder
The seeder is only available on the server so make sure it is placed somewhere in the server/ directory or check Meteor.isServer
before running the seeder.
new Seeder({
collection: <CollectionVar>, // Must be a valid Mongo.Collection instance
total: <Number of Entries> // default to 1
});
When you define your collection schema with simple-schema, you can set a property in the schema definition for a field named seeder
which is a String
which defines the faker generator with dot notation.
If you want a firstName generated by faker, you can define the seeder to be seeder: 'name.firstName'
. The package uses this definition to invoke the faker generator like this - faker.name.firstName()
.
You can also generate fake related collection data. For example, If you have a Parents
collection and a Children
collection and in the Children
collection you want to store a the parent's id, you can do it by passing the Mongo.Collection
instance as seeder
. Storing multiple ids as array is also supported:
Parents = new Mongo.Collection('parents');
Children = new Mongo.Collection('children');
Children.attachSchema(new SimpleSchema({
firstName: {
type: String,
seeder: 'name.firstName'
},
parent: {
type: String,
seeder: Parents
}
}));
Below is a complete schema definition -
Items.attachSchema(new SimpleSchema({
title: {
type: String,
max: 20,
seeder: 'lorem.sentence'
},
color: {
type: String,
seeder: 'internet.color'
},
rating: {
type: Number,
max: 30
},
active: {
type: Boolean,
defaultValue: true
},
createdAt: {
type: Date
},
updatedAt: {
type: [Date]
}
}));
In the above example, you'll notice that some fields do not have the seeder property and this still works because even if there is no seeder set, the package will try it's best to generate the data using the type
property. (Please keep in mind that, for now the fallback support is very limited so it might not give you the expected dummy data).