0
votes

I have trouble understanding what MongoDB is doing with my queries. My documents contain almost exclusively array fields, keeping me from using compound indexes. every field is Indexed with ensureIndex({FieldName:1})

The queries are AND concatenated like that:

{$and: [{FIELD1:"field1Val"},{FIELD2:"field2Val"},{FIELD3:"field3Val"}]}

If i run this query, MongoDB appears to be using only one index. Why isn't MongoDB using all the Indexes in parallel and then intersects them?

The same problem solved with Lucene runs 8 times faster then my MongoDB implementaition does now.

1
It might not matter, but you don't need to use $and there. Just make it {FIELD1: 'field1Val', FIELD2: 'field2Val', FIELD3: 'field3Val'} and the optimizer may be able to do more.JohnnyHK
I second JohnnyHK on removing the $and because it's not helping. Also, it's very suspect to have mostly arrays in your documents. If you're having trouble with performance, could you post an example document, query, and an explain for the query?wdberkeley

1 Answers

0
votes

(Before v2.6, one of MongoDB's well-known limitation is that it can use only one index per query except some special cases using $or

To improve query speed, you can use hint() to enforce the index used. Choose the most seletive index.)

As the comments say, its no longer true. Use index intersection. It seems that u can use at most 2 index intersected. See : When are Compound Indexes still relevant in MongoDB 2.6, given the new Index Intersection feature?

@JohnnyHK Ty for the comments, it makes me learn new things.