Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb indexes covered queries

There is a sample http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/#indexes-covered-queries

any of the indexed fields are fields in subdocuments. To index fields in subdocuments, use dot notation. For example, consider a collection users with documents of the following form: { _id: 1, user: { login: "tester" } } The collection has the following indexes:

{ user: 1 }

{ "user.login": 1 }

The { user: 1 } index covers the following query:

db.users.find( { user: { login: "tester" } }, { user: 1, _id: 0 } )

However, the { "user.login": 1 } index does not cover the following query:

db.users.find( { "user.login": "tester" }, { "user.login": 1, _id: 0 } )

The query, however, does use the { "user.login": 1 } index to find matching documents.

I want to know the root-cause why the { "user.login": 1 } index does not cover the query.

Thank you

like image 362
Linlin Avatar asked Feb 16 '23 13:02

Linlin


1 Answers

The "root cause" is that this feature is not currently implemented. Specifically, the feature is SERVER-2104 and once that is implemented you will get the result you need (so go vote for it and watch it). In the mean time, to utilize covered index queries you need to avoid the use of sub-documents in the index.

like image 91
Adam Comerford Avatar answered Feb 28 '23 09:02

Adam Comerford