mongodb 3.0 기준으로 색인 타입(index type)이 무엇이 있는지 살펴보았다.
- 한 필드 색인 (Single Field Index)
- _id 라는 주요 식별자로 색인
{ "_id" : ObjectId(...), "name" : "Alice", "age" : 27 }
- 복합 색인 (Compound Index)
DB에서의 _id 외 여러 필드로 색인하는 형태, 여러 개의 키로 색인
{ "_id": ObjectId(...), "item": "Banana", "category": ["food", "produce", "grocery"], "location": "4th Street Store", "stock": 4, "type": "cases", "arrival": Date(...) }
db.products.createIndex( { "item": 1, "stock": 1 } )
- 멀티키 색인(Multikey Index)
- 배열에 색인을 사용하도록 함. 스칼라(integer, string) 타입 또는 내장 타입 사용 가능
db.coll.createIndex( { <field>: < 1 or -1 > } )
- 장소 색인 (Geospatial Indexes and Queries)
여러 장소 타입(flat, 2dsphere 등등)을 저장할 수 있고, 검색 가능
db.places.insert( { loc : { type: "Point", coordinates: [ -73.97, 40.77 ] }, name: "Central Park", category : "Parks" } )
db.places.createIndex( { loc : "2dsphere" } )
- 본문 색인 (Text Indexes)
- 본문 검색을 위해 사용한다.
db.reviews.createIndex( { comments: "text" } )
db.collection.createIndex( { "$**": "text" } )
- 해시 색인 (Hashed Index)
해시 색인을 생성한다.
db.active.createIndex( { a: "hashed" } )
출처 :
'mongodb' 카테고리의 다른 글
[mongodb] 검색하기- find(), findOne() (0) | 2015.10.11 |
---|---|
[mongodb] index (색인) 속성 (0) | 2015.10.09 |
[mongodb] collection의 항목 삭제 및 trucate하기 (0) | 2015.10.02 |
[mongodb] collection 하나 삭제하기 - quotation의 중요성 (0) | 2015.09.30 |
[mongdb] /etc/mongod.conf 주의 사항 (0) | 2015.09.30 |