Indexes mongodb?

Which indexes should be for such a request?

db.foo.find({
 $or : [ { a : 1 } , { b : 2 } ],
 c: {$lte: 3}
 }).sort( { c : -1 } )


Tried to be a pop up, do not see a clear dependence of the rate indexing for individual fields, or all together. Have any sense at all indexes in many fields. Thank you!
October 8th 19 at 02:29
3 answers
October 8th 19 at 02:31
> Have any sense at all indexes on multiple fields
has, if only on these fields, the search takes place. Example db.user.find({city:'Moscow', sex:0, age:18})
build sostavnoi index on the city field,sex,age
Adult virgin Moscow? :) - ignacio commented on October 8th 19 at 02:34
Worth filter on the floor :) - terrill_Sanford commented on October 8th 19 at 02:37
October 8th 19 at 02:33
Explain tried to watch?
I would like the theory to understand. When we use compound indexes. - ignacio commented on October 8th 19 at 02:36
Well below have already written that Yes, they are. Just there are situations (see blue note) when the index is, but it is not used. Therefore it is necessary to glance at the explain if there is suspicion. - terrill_Sanford commented on October 8th 19 at 02:39
All understood, thanks! - ignacio commented on October 8th 19 at 02:42
October 8th 19 at 02:35
Definitely need db.foo.ensureIndex({c:1})
Then create a large test sample, and are explain.

Find more questions by tags MongoDB