Abstract Class yii\mongodb\Migration
Inheritance | yii\mongodb\Migration » yii\base\Component |
---|---|
Implements | yii\db\MigrationInterface |
Available since version | 2.0 |
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 \yii\mongodb\up() method should be overridden to contain the logic for "upgrading" the database; while the \yii\mongodb\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
Property | Type | Description | Defined By |
---|---|---|---|
$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
Method | Description | Defined By |
---|---|---|
batchInsert() | Inserts several new rows into collection. | yii\mongodb\Migration |
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 |
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 |
init() | Initializes the migration. | yii\mongodb\Migration |
insert() | Inserts new data into collection. | yii\mongodb\Migration |
remove() | Removes data from the collection. | yii\mongodb\Migration |
save() | Update the existing database data, otherwise insert this data | yii\mongodb\Migration |
update() | Updates the rows, which matches given criteria by given data. | yii\mongodb\Migration |
Protected Methods
Method | Description | Defined By |
---|---|---|
composeCollectionLogName() | Composes string representing collection name. | yii\mongodb\Migration |
Property Details
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
Inserts several new rows into collection.
public 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. |
---|
Composes string representing collection name.
protected string composeCollectionLogName ( $collection ) | ||
$collection | array|string | Collection name. |
return | string | Collection name. |
---|
Creates new collection with the specified options.
public void createCollection ( $collection, $options = [] ) | ||
$collection | string|array | Name of the collection |
$options | array | Collection options in format: "name" => "value" |
Creates an index on the collection and the specified fields.
public 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. |
Drops all indexes for specified collection.
public void dropAllIndexes ( $collection ) | ||
$collection | string|array | Name of the collection. |
Drops existing collection.
public void dropCollection ( $collection ) | ||
$collection | string|array | Name of the collection |
Drop indexes for specified column(s).
public void dropIndex ( $collection, $columns ) | ||
$collection | string|array | Name of the collection |
$columns | string|array | Column name or list of column names. |
Initializes the migration.
This method will set $db to be the 'db' application component, if it is null.
public void init ( ) |
Inserts new data into collection.
public \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. |
---|
Removes data from the collection.
public 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. |
---|
Update the existing database data, otherwise insert this data
public \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. |
---|
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.
public 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. |
---|