Seeding the database when developing my application

I have a file that will generate some collections and seed them for my application to work when I am developing. This currently runs as server-side code every time the application starts/restarts, but I only want it to run when I start the application for the first time in my development environment, prior to coding, so that I know that the DB has all the structure in place. How best to do this?


import Fixtures from '../imports/startup/server/fixtures.js';

Meteor.startup(function () {

    var Fixture = new Fixtures;


Are you basically trying to run migrations? Basically, create a collection and write to it when you run the migration. Before you run the migration however, you check if there is a record in it. If there is, don’t run; otherwise, run and add the record.

There are a few migration packages on atmosphere you can look into as well.

Here’s one way to run migrations:

For fixtures, you can do something similar, where you set an environment variable like SETUP_FIXTURES=true meteor

So, bascially, I want to ensure that collections and records are in place (in my development environment), so that when am developing the application further (and testing as I go along), I have the correct data in Mongo for the application to work as expected.
Migrations sounds like the sort of thing I need to use. What would be ideal though is for the Migrations to run automatically, in the dev environment only and only run them once when I start the Meteor app for the first time, i.e. not get continually run each time I update the code.

I don’t think he is talking about migrations, he is talking about seeding the database with some data when no data exists.

To do that, you simply need to check if there is already data in your collections.

Something like this: Collection.find().count() === 0