1

What is the difference of a unique vs a non-unique index in Mongodb in terms of
1. write performance - i believe all indexes are defined as B-tree in mongodb.If so,is there any material difference between insert performance in a collection having one vs the other
2. read performance - is there any fundamental difference in the way a lookup/read is done between the two types of index.

IUnknown
  • 9,301
  • 15
  • 50
  • 76
  • It makes no difference whether they are unique or non-unique indexes either. In order for MongoDB to find out documents, it needs to do an index traversal which operates in O(N) – Valijon Jan 07 '20 at 17:14
  • Depends on how you define N there :) – Sergio Tulentsev Jan 07 '20 at 17:30
  • 2
    Write performance will be affected since mongo needs to confirm there is no other record with the value. Read performance is exactly the same as a non-unique index. I don't have exact numbers on this but I doubt you'll need to worry about it unless you're doing massive amounts of writes per second. – Plancke Jan 07 '20 at 17:35
  • That is exactly what I had confusion about - what is hte difference in complexity of search for a unique vs non-unique index during a write.In a B-tree ,it should be minimal ,if at all – IUnknown Jan 08 '20 at 02:08

0 Answers0