0

I have 3 different fields a, b, c in my collection X, where:

a -> short string/keyword, b -> url, c -> date

I have 2 queries which need a, b and a, c respectively.

My question is,

How to index properly to optimize both queries.


I have considered:

1) Two compound index of a+b and a+c

2) create 3 single key indexes for a, b, c and rely on index intersection.

3) create a compound index for a+b and a single index for c, and hope that c and prefix a will optimize the second query.

4) create a compound index for a+b+c (not sure about this)

What is the best solution and why?

Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
  • What kind of queries are these? The date is probably a range and returns many records? The keyword and URL are exact match returning many (keyword) and very few (URL)? – Thilo Dec 01 '18 at 11:44
  • well, the first query that uses `keyword + url` basically an upsert operation. And `date` is a range as you mentioned and so `date+keyword` returns many records. – Ahsanul Haque Dec 01 '18 at 11:53
  • Both `1` and `4` seem reasonable. – Thilo Dec 01 '18 at 13:17

0 Answers0