Abstract Class yii\mongodb\Migration

Inheritanceyii\mongodb\Migration » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable, yii\db\MigrationInterface
Available since version2.0
Source Code https://github.com/yiisoft/yii2-mongodb/blob/master/Migration.php

Migration is the base class for representing a MongoDB migration.

Each child class of Migration represents an individual MongoDB migration which is identified by the child class name.

Within each migration, the up() method should be overridden to contain the logic for "upgrading" the database; while the down() method for the "downgrading" logic.

Migration provides a set of convenient methods for manipulating MongoDB data and schema. For example, the createIndex() method can be used to create a collection index. Compared with the same methods in yii\mongodb\Collection, these methods will display extra information showing the method parameters and execution time, which may be useful when applying migrations.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$db yii\mongodb\Connection|array|string The MongoDB connection object or the application component ID of the MongoDB connection that this migration should work with. yii\mongodb\Migration

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
batchInsert() Inserts several new rows into collection. yii\mongodb\Migration
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\Object
createCollection() Creates new collection with the specified options. yii\mongodb\Migration
createIndex() Creates an index on the collection and the specified fields. yii\mongodb\Migration
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
down() This method contains the logic to be executed when removing this migration. yii\db\MigrationInterface
dropAllIndexes() Drops all indexes for specified collection. yii\mongodb\Migration
dropCollection() Drops existing collection. yii\mongodb\Migration
dropIndex() Drop indexes for specified column(s). yii\mongodb\Migration
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the migration. yii\mongodb\Migration
insert() Inserts new data into collection. yii\mongodb\Migration
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
remove() Removes data from the collection. yii\mongodb\Migration
save() Update the existing database data, otherwise insert this data yii\mongodb\Migration
trigger() Triggers an event. yii\base\Component
up() This method contains the logic to be executed when applying this migration. yii\db\MigrationInterface
update() Updates the rows, which matches given criteria by given data. yii\mongodb\Migration

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
composeCollectionLogName() Composes string representing collection name. yii\mongodb\Migration

Property Details

$db public property

The MongoDB connection object or the application component ID of the MongoDB connection that this migration should work with. Starting from version 2.0.2, this can also be a configuration array for creating the object.

Method Details

batchInsert() public method

Inserts several new rows into collection.

array batchInsert$collection$rows$options = [] )
$collection array|string

Collection name.

$rows array

Array of arrays or objects to be inserted.

$options array

List of options in format: optionName => optionValue.

return array

Inserted data, each row will have "_id" key assigned to it.

composeCollectionLogName() protected method

Composes string representing collection name.

string composeCollectionLogName$collection )
$collection array|string

Collection name.

return string

Collection name.

createCollection() public method

Creates new collection with the specified options.

void createCollection$collection$options = [] )
$collection string|array

Name of the collection

$options array

Collection options in format: "name" => "value"

createIndex() public method

Creates an index on the collection and the specified fields.

void createIndex$collection$columns$options = [] )
$collection string|array

Name of the collection

$columns array|string

Column name or list of column names.

$options array

List of options in format: optionName => optionValue.

dropAllIndexes() public method

Drops all indexes for specified collection.

void dropAllIndexes$collection )
$collection string|array

Name of the collection.

dropCollection() public method

Drops existing collection.

void dropCollection$collection )
$collection string|array

Name of the collection

dropIndex() public method

Drop indexes for specified column(s).

void dropIndex$collection$columns )
$collection string|array

Name of the collection

$columns string|array

Column name or list of column names.

init() public method

Initializes the migration.

This method will set $db to be the 'db' application component, if it is null.

void init( )
insert() public method

Inserts new data into collection.

\MongoId insert$collection$data$options = [] )
$collection array|string

Collection name.

$data array|object

Data to be inserted.

$options array

List of options in format: optionName => optionValue.

return \MongoId

New record id instance.

remove() public method

Removes data from the collection.

integer|boolean remove$collection$condition = [], $options = [] )
$collection array|string

Collection name.

$condition array

Description of records to remove.

$options array

List of options in format: optionName => optionValue.

return integer|boolean

Number of updated documents or whether operation was successful.

save() public method

Update the existing database data, otherwise insert this data

\MongoId save$collection$data$options = [] )
$collection array|string

Collection name.

$data array|object

Data to be updated/inserted.

$options array

List of options in format: optionName => optionValue.

return \MongoId

Updated/new record id instance.

update() public method

Updates the rows, which matches given criteria by given data.

Note: for "multiple" mode Mongo requires explicit strategy "$set" or "$inc" to be specified for the "newData". If no strategy is passed "$set" will be used.

integer|boolean update$collection$condition$newData$options = [] )
$collection array|string

Collection name.

$condition array

Description of the objects to update.

$newData array

The object with which to update the matching records.

$options array

List of options in format: optionName => optionValue.

return integer|boolean

Number of updated documents or whether operation was successful.