Hi, I have a database with millions of records, let’s say 1M for simplicity. Now I want to write a single find query on the basis of 4 fields: field1, field2, field3 and field4 ( db.collection.find({field1: val1, field2: val2, field3: val3, field4: val4})
). Currently fields 1 to 4 have single indexes on them. I have the following questions:
- How much difference will writing a compound index on all the 4 fields create in the response time, as compared to having just the 4 single indexes?
- With just the single indexes on the fields 1 to 4, does the order of writing the fields in the query affect the response time? If yes, then what should be the optimal strategy?