In my replica set mongodb cluster
, a read
query could occur:
- either on column1
- or on column2
- or on combination of column1 and column2
- or on combination of column1 and column3
- or on combination of column2 and column3
- or on combination of column1 and column2 and column3
Would it make sense to create 6 indexes for each case above or there is an efficient way to club these under lesser number of indexes?
An index on {column1: 1, column2: 1, column 3:1 }
can service queries on:
An index on {column2: 1, column3: 1}
can service queries on:
An index on {column3: 1, column1: 1}
can service queryies on:
All of your queries noted could be handled properly with 3 compound indexes.
If you do find it necessary to create lots of indexes, note that mongod has a limit of 64 indexes per collection.