보통은 인덱스를 먼저 생성하고 그 이후에 데이터를 추가하는 것이 일반적.

하지만, 데이터를 먼저 삽입하고 이후에 인덱스를 구축하는 경우도 있음

  1. 다른 DB에서 MongoDB로 옮겨올 경우
  2. 새로운 쿼리에 대한 최적화를 해야할 경우

인덱스 구축 단계

https://docs.mongodb.com/manual/core/index-creation/

인덱스 구축은 두 단계로 이루어 진다.

[conn1] building new index on { open: 1.0, close: 1.0 } for stocks.values
    1000000/4308303 23%
    2000000/4308303 46%
    3000000/4308303 69%
    4000000/4308303 92%
    Tur Jan 4 09:59:13 [conn1] external sort used : 5 files in 55secs
    1200300/4308303 27%
    2837100/4308303 51%
    3456000/4308303 77%
    4210200/4308303 95%
    Tur Jan 4 10:00:16 [conn1] done building bottom layer, going to commit
    Tur Jan 4 10:00:16 [conn1] done for 4308303 records 118.123secs
    Tur Jan 4 10:00:16 [conn1] insert socks.system.indexs 118123ms

이외에 currentOp() 를 사용하여 인덱스 생성의 진척도를 확인할수도 있다.

db.currentOp()