* 인덱스 확인

  > db.person.getIndexes()    //    Collection의 인덱스 확인

 

* 인덱스 생성

  > db.person.ensureIndex({name:1})    //    1이면 오름차순, -1 이면 내림차순

 

* 인덱스 생성(백그라운드에서 생성, 비동기방식)

  > db.person.ensureIndex({name:1},{background:true})

 

* 인덱스 생성( 고유인덱스 ) 

  > db.person.ensureIndex({name:1},{unique:true})    //    unique 속성을 지정해서 중복데이터가 저장되지 못하게 하여,

데이터 저장과 검색속도를 늘린다.

 

* 인덱스 생성( 중복데이터 삭제 )

  > db.person.ensureIndex({name:1},{unique:true, dropDups:true})    //    Unique 하게 했을 때 이미 중복된 데이터가 있을 경우 중복되는 데이터는 삭제하고 인덱스를 저장한다.

 

* 인덱스 삭제 ( 특정 필드 )

  > db.person.dropIndex({name:1})    //    해당 인덱스 제거

 

* 인덱스 삭제( 모든 인덱스)

  > db.person.dropIndexes()    //    _id를 제외한 모든 인덱스 제거



출처: https://givemesource.tistory.com/86?category=734442 [WITH US]

 

'Data Engineering > MongoDB' 카테고리의 다른 글

[MongoDB] Start/Stop  (0) 2020.09.14
[MongoDB] aggregate $lookup  (0) 2019.11.12
[MongoDB] 백업 및 복구  (0) 2019.11.05
[MongoDB] DB생성 관리  (0) 2019.11.05
[MongoDB] 데이터 관리  (0) 2019.11.04

+ Recent posts