Requirements

To use this class, you must have the PHP Mongo extension installed and enabled. For instance, to install the PECL package:

$ sudo pecl install mongo
$ sudo service apache2 restart

Usage

The MongoDB source must be instantiated with a collection and a query. This means that you should set up the database connection in your own migration class. You can also provide an array of desired fields, sort parameters, and options.

Example

In your migration constructor:

<?php
// Set source.
$db_string = 'mongodb://username:password@example.com:12345/database';
$m = new MongoClient($db_string);
$db = $m->database;
$collection = $db->rows;
$fields = array(
  '_id' => 'Object ID',
);
$query = array();
$sort = array(
  '_id' => 1,
);
$this->source = new MigrateSourceMongoDB($collection, $query, $fields, $sort);
// Set destination.
$this->destination = new MigrateDestinationNode('article');
// Set map.
$source_key = array(
  '_id' => array(
    'type' => 'varchar',
    'length' => 24,
    'not null' => TRUE,
    'description' => 'MongoDB ID field.',
  ),
);
$this->map = new MigrateSQLMap($this->machineName, $source_key, MigrateDestinationNode::getKeySchema());
?>