B
B
Boris192018-02-02 11:52:52
MongoDB
Boris19, 2018-02-02 11:52:52

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

8 answer(s)
D
Dmitry Tallmange, 2018-02-02
@Boris19

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 .

G
gunya, 2011-06-24
@gunya

I don't see it please show me

R
Rampage_Masta, 2011-06-24
@Rampage_Masta

It looks like the user himself is doing this, since “something” corrected the posts

B
blainer, 2011-06-24
@blainer

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.

V
VenomBlood, 2011-06-24
@VenomBlood

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.

V
Vilmas, 2011-06-26
@Vilmas

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).

S
sskalmykov, 2011-06-24
@sskalmykov

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.

A
atomlib, 2011-06-24
@atomlib

This could be called a "guard" if it were not done on the sly and later. Maybe the work of the author himself, or maybe the hacker of his account. In general, the administration should prohibit editing posts older than three days.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question