PHPackages                             devture/mongodb-migrations-bundle - 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. devture/mongodb-migrations-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

devture/mongodb-migrations-bundle
=================================

Symfony MongoDBMigrationsBundle

v5.0.2(5mo ago)8281.4k↓12.2%21MITPHPPHP ^7.1 || ^8.0

Since Sep 26Pushed 5mo agoCompare

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

READMEChangelogDependencies (6)Versions (18)Used By (1)

[![MIT license](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](http://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/6b89820df228c6498f0804edd7ca8656b5ae1c2378e2d0ba912ef63a6aff854c/68747470733a2f2f7472617669732d63692e6f72672f646576747572652f6d6f6e676f64622d6d6967726174696f6e732d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/devture/mongodb-migrations-bundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5fcc25c1741158d0aca447861105cceb49e162802599d1abbd190f8441f24e65/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646576747572652f6d6f6e676f64622d6d6967726174696f6e732d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/devture/mongodb-migrations-bundle/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f85528237d47aa29f01b7527abc04302d606a2fd2359a210f1bc933f52fffcc6/68747470733a2f2f706f7365722e707567782e6f72672f646576747572652f6d6f6e676f64622d6d6967726174696f6e732d62756e646c652f762f737461626c65)](https://packagist.org/packages/devture/mongodb-migrations-bundle)[![Total Downloads](https://camo.githubusercontent.com/7c075fa1df7c20436ea6cf68eb782f70ebbc5b3f89c46482f4c030717148db1b/68747470733a2f2f706f7365722e707567782e6f72672f646576747572652f6d6f6e676f64622d6d6967726174696f6e732d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/devture/mongodb-migrations-bundle)

MongoDB Migrations Bundle
=========================

[](#mongodb-migrations-bundle)

**2022-02-05**: This is a fork of the `antimattr/mongodb-migrations-bundle` library, which makes it work on PHP 8 and Symfony 6.

This bundle integrates the [MongoDB Migrations](https://github.com/doesntmattr/mongodb-migrations) library into Symfony to get you set up more quickly.

It was moved to the doesntmattr organisation from [antimattr/mongodb-migrations-bundle](https://github.com/antimattr/mongodb-migrations-bundle) to continue maintenance (See [issue 16](https://github.com/antimattr/mongodb-migrations/issues/16)).

The original authors are @rcatlin and @matthewfitz

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.

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

[](#installation)

Install with composer:

```
composer require "doesntmattr/mongodb-migrations-bundle=^4.0"
```

then enable the bundle in `AppKernel.php` by including the following:

```
// app/AppKernel.php
public function registerBundles()
{
    $bundles = [
        //...
        new AntiMattr\Bundle\MongoDBMigrationsBundle\MongoDBMigrationsBundle(),
    ];
}
```

Configuration
-------------

[](#configuration)

Add following configuration lines to `config.yml` file.

```
# app/config/config.yml
mongo_db_migrations:
    collection_name: "migration_versions"
    database_name: "opensky_devo"
    dir_name: "%kernel.project_dir%/src/OpenSky/Bundle/MainBundle/Migrations/MongoDB"
    script_dir_name: "%kernel.project_dir%/scripts"
    name: "OpenSky DEVO MongoDB Migrations"
    namespace: "OpenSky\\Bundle\\MainBundle\\MigrationsMongoDB"
```

Container Aware Migrations
--------------------------

[](#container-aware-migrations)

In some cases you might want to access some services you have defined in the container. For example you may want to use a Factory to create new entities in the structure you need.

To get access to the container simply implement the ContainerAwareInterface including the required method `setContainer()`:

```
// ...
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class Version20130326212938 extends AbstractMigration implements ContainerAwareInterface
{
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function up(Database $db)
    {
        // ... migration content
    }

    public function postUp(Database $db)
    {
        $dm = $this->container->get('doctrine.odm.default_document_manager');
        // ... update the entities
    }
}
```

MongoDB Cursor Timeouts
-----------------------

[](#mongodb-cursor-timeouts)

In some cases you may need the Cursor timeout to be extended. If so, add the MongoDB option `['socketTimeoutMs' => -1]` to your update method.

Features
--------

[](#features)

For a full list of available features, see the README.md in the MongoDB Migrations library:

Differences from the underlying library are limited to the Console commands, namely database configurations are handled by Symfony's Dependency injection container, so you don't pass them as command line args.

Examples of the Command Line args with the difference below:

### Generate a New Migration

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

```
> ./console mongodb:migrations:generate
Generated new migration class to "Example/Migrations/TestAntiMattr/MongoDB/Version20140822185742.php"
```

### Status of Migrations

[](#status-of-migrations)

```
> ./console mongodb:migrations:status

 == 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 Migrations

[](#migrate-all-migrations)

This is what you will execute during your deployment process.

```
./console mongodb:migrations:migrate

                    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 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)
```

Use `--replay` if you need to re-run an executed migration.

### 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 --delete 20140822185744
```

You can add

```
./console mongodb:migrations:version --add 20140822185744
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~255 days

Recently: every ~165 days

Total

17

Last Release

165d ago

Major Versions

1.2.0 → 2.02018-04-12

v2.0.1 → 3.0.02020-03-21

v3.0.1 → v4.0.02022-02-25

v4.1.2 → v5.0.02025-04-17

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

1.2.0PHP &gt;=5.6 || ^7.0

2.0PHP ^7.1

v4.0.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9daf523f8e47ddeb8af23183c06721c4e89111eb4eb3f9ce264242b373e9dd80?d=identicon)[spantaleev](/maintainers/spantaleev)

---

Top Contributors

[![redthor](https://avatars.githubusercontent.com/u/767896?v=4)](https://github.com/redthor "redthor (36 commits)")[![matthewfitz](https://avatars.githubusercontent.com/u/208401?v=4)](https://github.com/matthewfitz "matthewfitz (20 commits)")[![caciobanu](https://avatars.githubusercontent.com/u/3765656?v=4)](https://github.com/caciobanu "caciobanu (16 commits)")[![spantaleev](https://avatars.githubusercontent.com/u/388669?v=4)](https://github.com/spantaleev "spantaleev (12 commits)")[![arendjantetteroo](https://avatars.githubusercontent.com/u/713066?v=4)](https://github.com/arendjantetteroo "arendjantetteroo (5 commits)")[![emulienfou](https://avatars.githubusercontent.com/u/84061?v=4)](https://github.com/emulienfou "emulienfou (2 commits)")[![JoppeDC](https://avatars.githubusercontent.com/u/9723620?v=4)](https://github.com/JoppeDC "JoppeDC (1 commits)")[![graillus](https://avatars.githubusercontent.com/u/4977244?v=4)](https://github.com/graillus "graillus (1 commits)")[![trq](https://avatars.githubusercontent.com/u/32683?v=4)](https://github.com/trq "trq (1 commits)")[![tychris](https://avatars.githubusercontent.com/u/7794059?v=4)](https://github.com/tychris "tychris (1 commits)")

---

Tags

symfonymigrationdatabasedoctrinemongodbantimattrdoesntmattr

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[doesntmattr/mongodb-migrations-bundle

Symfony MongoDBMigrationsBundle

23484.5k1](/packages/doesntmattr-mongodb-migrations-bundle)[doesntmattr/mongodb-migrations

Managed Database Migrations for MongoDB

23598.7k1](/packages/doesntmattr-mongodb-migrations)[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-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)

PHPackages © 2026

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