PHP Класс yii\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 Migration::createIndex method can be used to create a collection index. Compared with the same methods in Collection, these methods will display extra information showing the method parameters and execution time, which may be useful when applying migrations.
С версии: 2.0
Автор: Klimov Paul ([email protected])
Наследование: extends yii\base\Component, implements yii\db\MigrationInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$db 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.

Открытые методы

Метод Описание
batchInsert ( array | string $collection, array $rows, array $options = [] ) : array Inserts several new rows into collection.
createCollection ( string | array $collection, array $options = [] ) Creates new collection with the specified options.
createIndex ( string | array $collection, array | string $columns, array $options = [] ) Creates an index on the collection and the specified fields.
createIndexes ( string | array $collection, array $indexes ) Creates indexes in the collection.
dropAllIndexes ( string | array $collection ) Drops all indexes for specified collection.
dropCollection ( string | array $collection ) Drops existing collection.
dropIndex ( string | array $collection, string | array $columns ) Drop indexes for specified column(s).
dropIndexes ( string | array $collection, string $indexes ) Drops collection indexes by name.
init ( ) Initializes the migration.
insert ( array | string $collection, array | object $data, array $options = [] ) : MongoDB\BSON\ObjectID Inserts new data into collection.
remove ( array | string $collection, array $condition = [], array $options = [] ) : integer | boolean Removes data from the collection.
save ( array | string $collection, array | object $data, array $options = [] ) : MongoDB\BSON\ObjectID Update the existing database data, otherwise insert this data
update ( array | string $collection, array $condition, array $newData, array $options = [] ) : integer | boolean Updates the rows, which matches given criteria by given data.

Защищенные методы

Метод Описание
beginProfile ( string $token ) Marks the beginning of a code block for profiling.
composeCollectionLogName ( array | string $collection ) : string Composes string representing collection name.
endProfile ( string $token ) Marks the end of a code block for profiling.
log ( string $string ) Logs the incoming message.

Описание методов

batchInsert() публичный Метод

Inserts several new rows into collection.
public batchInsert ( array | string $collection, array $rows, array $options = [] ) : array
$collection array | string collection name.
$rows array array of arrays or objects to be inserted.
$options array list of options in format: optionName => optionValue.
Результат array inserted data, each row will have "_id" key assigned to it.

beginProfile() защищенный Метод

Marks the beginning of a code block for profiling.
С версии: 2.1.1
protected beginProfile ( string $token )
$token string token for the code block.

composeCollectionLogName() защищенный Метод

Composes string representing collection name.
protected composeCollectionLogName ( array | string $collection ) : string
$collection array | string collection name.
Результат string collection name.

createCollection() публичный Метод

Creates new collection with the specified options.
public createCollection ( string | array $collection, array $options = [] )
$collection string | array name of the collection
$options array collection options in format: "name" => "value"

createIndex() публичный Метод

Creates an index on the collection and the specified fields.
public createIndex ( string | array $collection, array | string $columns, array $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.

createIndexes() публичный Метод

Creates indexes in the collection.
С версии: 2.1
public createIndexes ( string | array $collection, array $indexes )
$collection string | array name of the collection
$indexes array indexes specifications.

dropAllIndexes() публичный Метод

Drops all indexes for specified collection.
public dropAllIndexes ( string | array $collection )
$collection string | array name of the collection.

dropCollection() публичный Метод

Drops existing collection.
public dropCollection ( string | array $collection )
$collection string | array name of the collection

dropIndex() публичный Метод

Drop indexes for specified column(s).
public dropIndex ( string | array $collection, string | array $columns )
$collection string | array name of the collection
$columns string | array column name or list of column names.

dropIndexes() публичный Метод

Drops collection indexes by name.
С версии: 2.1
public dropIndexes ( string | array $collection, string $indexes )
$collection string | array name of the collection
$indexes string wildcard for name of the indexes to be dropped.

endProfile() защищенный Метод

Marks the end of a code block for profiling.
С версии: 2.1.1
protected endProfile ( string $token )
$token string token for the code block.

init() публичный Метод

This method will set [[db]] to be the 'db' application component, if it is null.
public init ( )

insert() публичный Метод

Inserts new data into collection.
public insert ( array | string $collection, array | object $data, array $options = [] ) : MongoDB\BSON\ObjectID
$collection array | string collection name.
$data array | object data to be inserted.
$options array list of options in format: optionName => optionValue.
Результат MongoDB\BSON\ObjectID new record id instance.

log() защищенный Метод

By default this method sends message to 'stdout'.
С версии: 2.1.1
protected log ( string $string )
$string string message to be logged.

remove() публичный Метод

Removes data from the collection.
public remove ( array | string $collection, array $condition = [], array $options = [] ) : integer | boolean
$collection array | string collection name.
$condition array description of records to remove.
$options array list of options in format: optionName => optionValue.
Результат integer | boolean number of updated documents or whether operation was successful.

save() публичный Метод

Update the existing database data, otherwise insert this data
public save ( array | string $collection, array | object $data, array $options = [] ) : MongoDB\BSON\ObjectID
$collection array | string collection name.
$data array | object data to be updated/inserted.
$options array list of options in format: optionName => optionValue.
Результат MongoDB\BSON\ObjectID updated/new record id instance.

update() публичный Метод

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 update ( array | string $collection, array $condition, array $newData, array $options = [] ) : integer | boolean
$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.
Результат integer | boolean number of updated documents or whether operation was successful.

Описание свойств

$db публичное свойство

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.
public $db