Yii2 Mongodb 迁移
Yii2 Mongodb Migration
在我的 yii2 项目中,我有一些 mongodb 集合及其迁移。
我想要一个示例代码,它在一个集合上创建多个索引,并且
我也想知道是否有一种方法可以在 mongo 中定义列数据类型?
MongoDB 是 noSql,因此每个文档的结构都可以不同。不知道您的文档结构,就不可能创建任何示例代码。索引创建很简单,您的集合可以拥有多少个索引没有真正的限制。每个文档都不需要有那些索引键值对。
在 MongoDB 没有固定的键(列)类型。您可以插入:
x:1
x:longInt(1)
×:“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)
在我的 yii2 项目中,我有一些 mongodb 集合及其迁移。 我想要一个示例代码,它在一个集合上创建多个索引,并且 我也想知道是否有一种方法可以在 mongo 中定义列数据类型?
MongoDB 是 noSql,因此每个文档的结构都可以不同。不知道您的文档结构,就不可能创建任何示例代码。索引创建很简单,您的集合可以拥有多少个索引没有真正的限制。每个文档都不需要有那些索引键值对。
在 MongoDB 没有固定的键(列)类型。您可以插入: x:1 x:longInt(1) ×:“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)