0

I have a field "productLowerCase" in my mongo documents. I created 2 indices

1. simple
   {"productLowerCase" : 1}
2. compound
   {"productLowerCase" : 1, "timestamp.milliseconds" : -1}

So If I run a query which has only productLowerCase, say:

db.coll.find({"productLowerCase" : {$regex : /^cap/}})

Which index will get used?

1 Answers1

0

In this case mongo will use {"productLowerCase" : 1} this index, but you can remove this index, because if you have compound index you can search with first field without performance loss.

Beside this you can use explain() to explain your query.

andranikasl
  • 1,242
  • 9
  • 10