Answer the question
In order to leave comments, you need to log in
Can't figure out how indexes work in MongoDB?
I'm learning indexing in MongoDB, the following questions arose:
1) If there are two conflicting indexes, how does mongo determine which index to select from?
For example, suppose there is a collection with documents of the form {'name': 'VasyaPupkin', 'age': 30}. There are two indices {'name': 1, 'age': -1} and {'name': -1, 'age': -1}. We make a selection db.users.find({"name": "???"}). What index will be used?
2) Does the order of keys in a composite index matter?
3) Is there a connection between indexes and sort indication (find(...).sort(...)) in the query?
Answer the question
In order to leave comments, you need to log in
1) There will be no "contradictory" indexes. Possible, for example, redundant.
and
these are two different indexes.
I won't tell you about the intricacies of the query optimizer, but I'm sure Monga is smart enough to use exactly the index that is needed at the moment. Here it is superbly painted how Monga analyzes requests.
2) Of course yes. If we are compiling an index
, then in this order we must submit the elements in the query, otherwise the index will be useless.
3) If I understand the question correctly, the index is needed specifically for searching and sorting .
It looks like the user himself is doing this, since “something” corrected the posts
Current issue? Did you write to chip and dale? It would also be nice to create a post on this topic - not everyone reads q&a.
It is necessary to write to the chip and the dale - and more efficiently, and the seo's specialist will not be able to remove the links in advance.
All the same, not so many people read the old posts, for that the authors of the articles get at least some profit, so I don’t blame them (I remember that there is a “PPA”, which is not available to everyone).
Yeah, and here, too, habrahabr.ru/blogs/it_bigraphy/64008/ and here habrahabr.ru/blogs/crazydev/62058/ and in a couple of posts. It's not very good somehow, shitting in such a decent place.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question