in my yii2 project I have some mongodb collections and their migrations. I want to have a sample code which create multiple index on a collection and also I want to know is there an approach to define columns data type in mongo at all?
MongoDB is noSql, so every document can be structured differently. Without knowing your documents structure, it's impossible to create any sample code. Index creation is simple and there is no real limit how many indexes your collection can have. Every document don't need to have those indexed key - value pairs.
At MongoDB there is no fixed type for key (column). You can insert: x:1 x:longInt(1) x:"1" and you have three documents, witch every one have different type of key x.
To answer your second question...
/**
* Builds and executes a SQL statement for creating a new index.
* @param string $name the name of the index. The name will be properly quoted by the method.
* @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
* @param string $column the column(s) that should be included in the index. If there are multiple columns, please separate them
* by commas. The column names will be properly quoted by the method.
* @param boolean $unique whether to add UNIQUE constraint on the created index.
*/
public function createIndex($name, $table, $column, $unique = false)