2016-09-13 2 views
0

내 yii2 프로젝트에 mongodb 컬렉션과 마이그레이션이 있습니다. 컬렉션에 여러 개의 인덱스를 만드는 예제 코드가 있고 도 알고 싶습니다. mongo에서 열 데이터 형식을 정의하는 방법이 있습니까?Yii2 Mongodb Migration

답변

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) 
+0

덕분에 두 번째 질문에 대한 답을뿐만 아니라 나는 yii2 MongoDB의 마이그레이션에 인덱스를 생성하는 방법을 알고 싶었다. – mhndev