Yii2 Mongodb迁移

时间:2016-09-13 06:59:07

标签: mongodb yii2 migration mongodb-indexes

在我的yii2项目中,我有一些mongodb集合及其迁移。 我想有一个示例代码,在集合上创建多个索引 我还想知道是否有一种方法可以在mongo中定义列数据类型?

1 个答案:

答案 0 :(得分:1)

MongoDB是noSql,因此每个文档的结构可能不同。在不知道您的文档结构的情况下,无法创建任何示例代码。索引创建很简单,并且没有真正限制您的集合可以拥有多少索引。每个文档都不需要拥有那些索引的键 - 值对。

在MongoDB中,键(列)没有固定类型。你可以插入: X:1 X:Longint型(1) X:" 1" 你有三个文件,每个文件都有不同类型的密钥x。

回答你的第二个问题......

/**
     * 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)