2

I have a collection having about 10 million records. And I have a field key1 defined for round about 50,000 records. Now if I wish to index upon key1 how much space would actually be allotted. I mean would it be of order of 10 million units approx or 50,000 units for that index.

Also how does mongo manages index if values corresponding to key is of different type. For example. Lets say we have key2 for which we have 1,000 records storing strings, while other 1,000 records storing array. So how would index be created if one creates an index on key2.

My first question is a genuine problem I wish to get resolved. Second one is just for curiosity sake.

Sushant Gupta
  • 8,980
  • 5
  • 43
  • 48
  • 6
    you might check this answer to satisfy your curiosity :) http://stackoverflow.com/questions/4887727/mongodb-index-on-different-types – Asya Kamsky Nov 23 '12 at 03:41

1 Answers1

1

I found the answer to my question. Mongodb supports sparse indexes to only consider records having that key existing in order to be in the index. Sparse index won't index records which don't have that key existing. So if we set sparse = true while creating index on key1 then space allotted would be of order of 50,000 units approx.

Sushant Gupta
  • 8,980
  • 5
  • 43
  • 48