mongodb의 db.collection.ensureIndex()는 특정 collection의 특정 필드를 색인할 수 있었다.


> db.user.name.ensureIndex( {KEY:1} )
{
    "createdCollectionAutomatically" : true,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1

}



3.0.0 부터 db.collection.ensureIndex는 deprecated되었고, db.collection.createIndex로 쓰도록 권고하고 있다.


Deprecated since version 3.0.0: db.collection.ensureIndex() is now an alias fordb.collection.createIndex().

http://docs.mongodb.org/manual/reference/method/db.collection.ensureIndex/




3.0.0 부터는 db.collection.createIndex()를 사용한다. 관련 옵션은 기존의 ensureIndex와 동일하지만 dropDups는 제외되었다. 


http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/#ensureindex-options



중요한 매개변수 중 주요 매개변수를 설명한다.


- background : 색인 생성시 너무 많은 부하를 발생하지 않도록 background로 실행하도록 한다.

- unique : 중복 금지

- expireAfterSeconds : TTL 설정시 유효한 값



이전 예시를 다음과 같이 표현할 수 있다.


> db.user.name.createIndex( {name:"text"} );

{

"createdCollectionAutomatically" : true,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1

}




'mongodb' 카테고리의 다른 글

[mongodb] collection 개수 구하기  (0) 2015.10.12
[mongodb] 모니터링하기  (0) 2015.10.12
[mongodb] insert와 save의 차이점  (0) 2015.10.11
[mongodb] 검색하기- find(), findOne()  (0) 2015.10.11
[mongodb] index (색인) 속성  (0) 2015.10.09
Posted by '김용환'
,