PHPackages                             zp/mongodb-migrations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zp/mongodb-migrations

ActiveLibrary[Database &amp; ORM](/categories/database)

zp/mongodb-migrations
=====================

Managed Database Migrations for MongoDB

v4.0.1(4y ago)12551[1 PRs](https://github.com/zarplata/mongodb-migrations/pulls)MITPHPPHP ^7.1 || ^8.0

Since Sep 26Pushed 4y agoCompare

[ Source](https://github.com/zarplata/mongodb-migrations)[ Packagist](https://packagist.org/packages/zp/mongodb-migrations)[ Docs](http://github.com/doesntmattr/mongodb-migrations)[ RSS](/packages/zp-mongodb-migrations/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (16)Used By (0)

[![MIT license](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](http://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/5195ece0e1869fa7730fdbb3802f016494cd1669daaf4af92cafa97900c06040/68747470733a2f2f7472617669732d63692e6f72672f646f65736e746d617474722f6d6f6e676f64622d6d6967726174696f6e732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/doesntmattr/mongodb-migrations)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dfdc0b5571fdd79097c231b415e9ebe50396c8efee013bda9792eaafdedae453/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646f65736e746d617474722f6d6f6e676f64622d6d6967726174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/doesntmattr/mongodb-migrations/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/e5a88f605a9b2fd8ff186d6d01fe24b703f95b865861497d7191ff99c2bfd4d0/68747470733a2f2f706f7365722e707567782e6f72672f646f65736e746d617474722f6d6f6e676f64622d6d6967726174696f6e732f762f737461626c65)](https://packagist.org/packages/doesntmattr/mongodb-migrations)[![Total Downloads](https://camo.githubusercontent.com/e221a259cc3a0945cf6c3f26cb8bf9fddc116d9f50516413b0c03ff09ed7a062/68747470733a2f2f706f7365722e707567782e6f72672f646f65736e746d617474722f6d6f6e676f64622d6d6967726174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/doesntmattr/mongodb-migrations)

MongoDB Migrations
==================

[](#mongodb-migrations)

The MongoDB Migration library provides managed migration support for MongoDB. It was moved to the doesntmattr organisation from [antimattr/mongodb-migrations](https://github.com/antimattr/mongodb-migrations) to continue maintenance (See [issue 16](https://github.com/antimattr/mongodb-migrations/issues/16)).

The original authors are @rcatlin and @matthewfitz

It follows the structure and features provided by [Doctrine Migrations](https://github.com/doctrine/migrations).

PHP Version Support
-------------------

[](#php-version-support)

If you require php 5.6 support use version `^1.0`. Version `^3.0` requires at least php 7.1. The `1.x` releases will only receive bug fixes.

Symfony Bundle
--------------

[](#symfony-bundle)

There is a Symfony Bundle you can install to more easily integrate with Symfony. Use the installation instructions there:

Installation
------------

[](#installation)

To install with composer:

```
# For php 5.6
composer require "doesntmattr/mongodb-migrations=^1.0"

# For php 7.1
composer require "doesntmattr/mongodb-migrations=^3.0"
```

Features
--------

[](#features)

### Configuration

[](#configuration)

Similar to [Doctrine Migrations](https://github.com/doctrine/migrations), configuration is separated into 2 files:

- Connection configuration (php)
- Migration configuration (xml or yaml)

Example connection configuration "test\_antimattr\_mongodb.php":

```
/**
 * @link http://php.net/manual/en/mongoclient.construct.php
 */
return [
    'host' => 'localhost', // default is localhost
    'port' => '27017', // default is 27017
    'dbname' => null, // optional, if authentication DB is required
    'user' => null, // optional, if authentication is required
    'password' => null, // optional, if authentication is required
    'options' => [
        'connect' => true // recommended
    ]
];
```

XML or YAML migration configuration files are supported.

Example XML "test\_antimattr\_mongodb.xml":

```

    AntiMattr Sandbox Migrations
    AntiMattrMigrationsTest

    /path/to/migrations/classes/AntiMattrMigrations

    /path/to/migrations/script_directory

```

Example YAML "test\_antimattr\_mongodb.yml":

```
---
name: AntiMattr Sandbox Migrations
migrations_namespace: AntiMattrMigrationsTest
database: test_antimattr_migrations
collection_name: antimattr_migration_versions_test
migrations_directory: /path/to/migrations/classes/AntiMattrMigrations
migrations_script_directory: /path/to/migrations/script_directory # optional
```

### Console Command Support

[](#console-command-support)

There is an example Console Application in the `/demo` directory.

This is how you can register commands in your application:

```
require '../../vendor/autoload.php';

error_reporting(E_ALL & ~E_NOTICE);

use AntiMattr\MongoDB\Migrations\Tools\Console\Command as AntiMattr;
use Symfony\Component\Console\Application;

$application = new Application();
$application->addCommands([
    new AntiMattr\ExecuteCommand(),
    new AntiMattr\GenerateCommand(),
    new AntiMattr\MigrateCommand(),
    new AntiMattr\StatusCommand(),
    new AntiMattr\VersionCommand()
]);
$application->run();
```

Notice the console is executable:

```
> cd demo/ConsoleApplication/
> ./console
Console Tool

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.

Available commands:
  help                          Displays help for a command
  list                          Lists commands
mongodb
  mongodb:migrations:execute    Execute a single migration version up or down manually.
  mongodb:migrations:generate   Generate a blank migration class.
  mongodb:migrations:migrate    Execute a migration to a specified version or the latest available version.
  mongodb:migrations:status     View the status of a set of migrations.
  mongodb:migrations:version    Manually add and delete migration versions from the version table.
```

### Generate a New Migration

[](#generate-a-new-migration)

```
> ./console mongodb:migrations:generate --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml
Generated new migration class to "Example/Migrations/TestAntiMattr/MongoDB/Version20140822185742.php"
```

### Migrations Status

[](#migrations-status)

```
> ./console mongodb:migrations:status --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml

 == Configuration

    >> Name:                                AntiMattr Example Migrations
    >> Database Driver:                     MongoDB
    >> Database Name:                       test_antimattr_migrations
    >> Configuration Source:                demo/ConsoleApplication/config/test_antimattr_mongodb.yml
    >> Version Collection Name:             migration_versions
    >> Migrations Namespace:                Example\Migrations\TestAntiMattr\MongoDB
    >> Migrations Directory:                Example/Migrations/TestAntiMattr/MongoDB
    >> Current Version:                     0
    >> Latest Version:                      2014-08-22 18:57:44 (20140822185744)
    >> Executed Migrations:                 0
    >> Executed Unavailable Migrations:     0
    >> Available Migrations:                3
    >> New Migrations:                      3
```

### Migrate all

[](#migrate-all)

This is what you will execute during your deployment process.

```
./console mongodb:migrations:migrate --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml

                    AntiMattr Example Migrations

WARNING! You are about to execute a database migration that could result in data lost. Are you sure you wish to continue? (y/n)y
Migrating up to 20140822185744 from 0

  ++ migrating 20140822185742

     Collection test_a

     metric           before               after                difference
     ================================================================================
     count            100                  100                  0
     size             20452                20452                0
     avgObjSize       204.52               204.52               0
     storageSize      61440                61440                0
     numExtents       2                    2                    0
     nindexes         1                    2                    1
     lastExtentSize   49152                49152                0
     paddingFactor    1                    1                    0
     totalIndexSize   8176                 16352                8176

  ++ migrated (0.03s)

  ++ migrating 20140822185743

  ++ migrated (0s)

  ++ migrating 20140822185744

  ++ migrated (0s)

  ------------------------

  ++ finished in 0.03
  ++ 3 migrations executed
```

### Execute a Single Migration

[](#execute-a-single-migration)

```
./console mongodb:migrations:execute --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml 20140822185742
WARNING! You are about to execute a database migration that could result in data lost. Are you sure you wish to continue? (y/n)y

  ++ migrating 20140822185742

     Collection test_a

     metric           before               after                difference
     ================================================================================
     count            100                  100                  0
     size             20620                20620                0
     avgObjSize       206.2                206.2                0
     storageSize      61440                61440                0
     numExtents       2                    2                    0
     nindexes         1                    2                    1
     lastExtentSize   49152                49152                0
     paddingFactor    1                    1                    0
     totalIndexSize   8176                 16352                8176

  ++ migrated (0.02s)
```

If you need to run a migration again, you can use the `--replay` argument.

### Version Up or Down

[](#version-up-or-down)

Is your migration history out of sync for some reason? You can manually add or remove a record from the history without running the underlying migration.

You can delete:

```
./console mongodb:migrations:version --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml --delete 20140822185744
```

You can add:

```
./console mongodb:migrations:version --db-configuration=config/test_antimattr_mongodb.php --configuration=config/test_antimattr_mongodb.yml --add 20140822185744
```

### Analyze Migrations

[](#analyze-migrations)

Identify the collections you want to analyze. Statistics will be captured before and after the migration is run.

```
class Version20140822185742 extends AbstractMigration
{
    public function up(Database $db)
    {
        $testA = $db->selectCollection('test_a');
        $this->analyze($testA);

        // Do the migration
    }
```

### Execute JS Scripts

[](#execute-js-scripts)

First identify the directory for scripts in your Migration Configuration:

```
---
name: AntiMattr Sandbox Migrations
migrations_namespace: AntiMattrMigrationsTest
database: test_antimattr_migrations
collection_name: antimattr_migration_versions_test
migrations_directory: /path/to/migrations/classes/AntiMattrMigrations
migrations_script_directory: /path/to/migrations/script_directory # optional
```

Then execute the scripts via `AbstractMigration::executeScript()`:

```
class Version20140822185743 extends AbstractMigration
{
    public function up(Database $db)
    {
        $result = $this->executeScript($db, 'test_script.js');
    }
```

Contributing
------------

[](#contributing)

### PSR Standards

[](#psr-standards)

There is a git pre-commit hook that will fix all your contributed code to PSR standards.

You can install it with:

```
./bin/install.sh
Copying /antimattr-mongodb-migrations/bin/pre-commit.sh -> /antimattr-mongodb-migrations/bin/../.git/hooks/pre-commit
```

### Testing

[](#testing)

Tests should pass:

```
$ ./vendor/bin/phpunit
```

### Code Sniffer and Fixer

[](#code-sniffer-and-fixer)

If you didn't install the git pre-commit hook then ensure you run the fixer/sniffer manually:

```
$ vendor/bin/php-cs-fixer fix src/
$ vendor/bin/php-cs-fixer fix tests/
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 53.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~200 days

Recently: every ~328 days

Total

14

Last Release

1642d ago

Major Versions

1.2.2 → 2.0.02018-04-12

2.0.1 → 3.0.02020-03-21

3.0.0 → v4.0.02021-10-27

PHP version history (5 changes)v1.0.0PHP &gt;=5.3.2

1.2.1PHP &gt;=5.4.45

1.2.2PHP ^5.6|^7.1

2.0.0PHP ^7.1

v4.0.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/524901?v=4)[Vladimir Komissarov](/maintainers/idr0id)[@idr0id](https://github.com/idr0id)

---

Top Contributors

[![redthor](https://avatars.githubusercontent.com/u/767896?v=4)](https://github.com/redthor "redthor (111 commits)")[![rcatlin](https://avatars.githubusercontent.com/u/1914706?v=4)](https://github.com/rcatlin "rcatlin (29 commits)")[![caciobanu](https://avatars.githubusercontent.com/u/3765656?v=4)](https://github.com/caciobanu "caciobanu (25 commits)")[![matthewfitz](https://avatars.githubusercontent.com/u/208401?v=4)](https://github.com/matthewfitz "matthewfitz (18 commits)")[![arendjantetteroo](https://avatars.githubusercontent.com/u/713066?v=4)](https://github.com/arendjantetteroo "arendjantetteroo (15 commits)")[![w473](https://avatars.githubusercontent.com/u/10176704?v=4)](https://github.com/w473 "w473 (5 commits)")[![idr0id](https://avatars.githubusercontent.com/u/524901?v=4)](https://github.com/idr0id "idr0id (3 commits)")[![trq](https://avatars.githubusercontent.com/u/32683?v=4)](https://github.com/trq "trq (2 commits)")[![metanav](https://avatars.githubusercontent.com/u/7456984?v=4)](https://github.com/metanav "metanav (1 commits)")

---

Tags

migrationdatabasedoctrinemongodbantimattrdoesntmattr

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/zp-mongodb-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/zp-mongodb-migrations/health.svg)](https://phpackages.com/packages/zp-mongodb-migrations)
```

###  Alternatives

[doesntmattr/mongodb-migrations

Managed Database Migrations for MongoDB

23598.7k1](/packages/doesntmattr-mongodb-migrations)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[doesntmattr/mongodb-migrations-bundle

Symfony MongoDBMigrationsBundle

23484.5k1](/packages/doesntmattr-mongodb-migrations-bundle)[webonaute/doctrine-fixtures-generator-bundle

Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.

67184.1k](/packages/webonaute-doctrine-fixtures-generator-bundle)[perplorm/perpl

Perpl is an improved and still maintained fork of Propel2, an open-source Object-Relational Mapping (ORM) for PHP.

203.7k](/packages/perplorm-perpl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
