How to force use of indices in MongoDB?

466 views Asked by At

How could we make MongoDB report errors for queries that don't use indices?

We end up creating indices for every query anyway so it would be great if MongoDB would report missing indices for us. Also it would be convenient to be able to configure the restriction on a connection basis. This way indices wouldn't come into our way when working from MongoDB shell.

1

There are 1 answers

1
Sammaye On BEST ANSWER

The notablescan ( http://docs.mongodb.org/manual/reference/parameters/#param.notablescan ) option for the MongoDB binary (mongod.exe or mongod depending on your OS) allows you to stop any query, with an emitted log error, which does not use an index at all.

This option will not stop inefficient queries though so that part will still need to be discovered manually by you.