PHP code example of datingvip / php-mongo-migrator
1. Go to this page and download the library: Download datingvip/php-mongo-migrator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datingvip / php-mongo-migrator example snippets
class RevisionName extends \Sokil\Mongo\Migrator\AbstractMigration
{
public function up()
{
}
public function down()
{
}
}
class RevisionName extends \Sokil\Mongo\Migrator\AbstractMigration
{
protected function init()
{
// some common code
}
public function up()
{
$collection = $this
->getDatabase('some_database')
->getCollection('come_collection');
// create new field in all documents of collection
$collection->updateAll(function($operator) {
$operator->set('newField', 'defaultValue')
});
}
public function down()
{
$collection = $this
->getDatabase('some_database')
->getCollection('come_collection');
// create new field in all documents of collection
$collection->updateAll(function($operator) {
$operator->unsetField('newField')
});
}
}
composer
phive install sokil/php-mongo-migrator
composer
pc:~/php-mongo-migrator$ ./bin/mongo-migrator create RevisionName
New migration created at ~/php-mongo-migrator/migrations/20151127093706_RevisionName.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.