Creating index takes very long time

Background indexes also have some issues.

  1. If anything it should take longer due to the load on your server.
  2. If interrupted for some reason it will restart as a foreground build

If you have a replica set I prefer to do a "rolling index build".

  1. Take a secondary out of replica set
  2. Build index
  3. Insert secondary back into replica set

I think this is the cleanest solution.


Nope, indexing is slow for large collections. You can create the indexing in the background as well:

db.my_coll.ensureIndex({words:1}, {background:true});

Creating the index in the background will be slower and result in a larger index. However, it won't be used until the indexing is complete, so in the meantime you'll be able to use the database normally and the indexing won't block.

Tags:

Mongodb