How to create an effective Index with this query?

Will This Query and Sort use the Indexing in mongoDB?

  • If we create the following index: { a: 1, b: 1, c: 1, d: 1 } Will the following query and sort operations  use the index?  db.collection.find({a:5,f:7,h:9).sort( { a:1 } )

  • Answer:

    cursor.explain() provides an information about the query plan. Just append ".explain()" to your query, and run it, and you'll figure out whether it's using your indices. For more information, refer to this document: http://docs.mongodb.org/manual/reference/method/cursor.explain/

Michael Spector at Quora Visit the source

Was this solution helpful to you?

Other answers

I do not think you got the request syntax fully right. In general it should use index. Best is to use explain to confirm. Use "hint" with explain, so it will not reevaluate query plan. Regards, Ron http://www.enteros.com

Ron Warshawsky

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.