A command-line tool for applying migrations to a MongoDB database

Installs: 338

Dependents: 1

Stars: 3

Watchers: 3

Forks: 2

Open Issues: 2

Language: PHP

1.3.9 2015-06-26 12:55 UTC


Build Status Code Coverage

A command-line tool for applying migrations to a MongoDB database. Migrations are non-linear, and can be tested by writing simple YML files.

Doctrine's Mongo abstraction layer is used to provide a clean database API. Mongrate does not use Doctrine's Mongo ODM - this is to avoid having to write mapping classes and to make it very quick to write migrations.

At the moment, Mongrate does not support applying migrations to multiple databases.

Example migrations can be found in resources/examples/.

Symfony 2 users can use MongrateBundle to integrate easily with a Symfony 2 project.

Table of content:


Mongrate is available via Composer.

Once you have downloaded Mongrate, run these commands:

php composer.phar install
chmod a+x mongrate
cp config/parameters.yml.dist config/parameters.yml

Edit config/parameters.yml and enter your MongoDB connection information.


Your parameters.yml you should have something similar to this.

    mongodb_server: 'mongodb://localhost:27017'
    mongodb_db: my_db
    migrations_directory: migrations
Parameter Required Description mongodb_server required URI for your mongodb server. mongodb_db required Database name. migrations_directory required The directory where your migration files are to be kept.

Note: Don't add a trailing slash in migrations_directory parameter value.


Generate Migration

To generate a migration file, with the name "UpdateAddressStructure":

./mongrate generate-migration UpdateAddressStructure

List Migrations

To list available migrations:

./mongrate list-migrations

Toggle Migration

To toggle a migration (useful while writing your migration):

./mongrate toggle 20140523_UpdateAddressStructure

Migrate up

To migrate up:

./mongrate up 20140523_UpdateAddressStructure

Migrate down

To migrate down:

./mongrate down 20140523_UpdateAddressStructure

Test Migration

To verify a migration with it's YML test files:

./mongrate test 20140523_UpdateAddressStructure (up|down|empty)

NOTE: If you leave migration type empty after the migration name it will test both migrations up and down.


Please submit pull requests on GitHub.

Project follow PSR2 standard.

When you do composer install it should set a git-precomit to help you follow the standards.

Install the Git pre-commit hook manually:

bash contrib/

How to run tests

To run the test suite, just run phpunit.

The tests use a database called mongrate_test in your local MongoDB server.