[mongodb] 3.0부터 ensureIndex는 deprecated됨
mongodb의 db.collection.ensureIndex()는 특정 collection의 특정 필드를 색인할 수 있었다.
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
}