0

Does anyone know of a way to run a query in MongoDB, and specify that a named index NOT be used?

We have multiple indexes on our data and there are situations where mongo is making a poor choice about which index to use to satisfy some types of queries. But we don't necessarily want to declare that a specific index be used. Only that we know which one is definitely a poor choice.

Using a named index is easy:

db.users.find({....}).hint( "index_name" )

Excluding a named index might look something like this:

db.users.find({....}).hint( "index_name", false)

Any insight is appreciated.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
BrentR
  • 878
  • 6
  • 20
  • I know of no way, 99.99% of the time you want to either exclude all indexes or include only one – Sammaye Sep 10 '13 at 13:29

1 Answers1

4

You can't exclude indexes, you can only specify the use of one. However, MongoDB empirically tests indexes with your query by checking the search speed of the query against all indexes. It then determines what index to use based on these results. Can you please run the query with .explain(true) to show all the query plans.

Regards, Charlie

Charlie Page
  • 251
  • 1
  • 3