I have a mongodb collection with about 100.000 documents. Each document has an array with about 20 elements. The array looks like this:

features: [
    "240473_Iron Gray",
    "9350_1920 x 1080",

This is my query:


features: {$all: ["9350_1366 x 768", "91135_IPS", "178874_Y", "36303_N"]}


This query is very fast (takes less than 1 second). But sometimes, in particular cases, gets very slow when I include a specific condition inside $all. I have no idea why this happens. When gets slow it takes more than 40 seconds. Always happens with the same extra condition. It is very possible that it happens with other strings.

In first place I indexed the field "features".

Also I order the $all elements for satisfy mongodb specificity. I got a little more performance, but keeps terribly slow. Last, I test to hash strings and keep short like "8f624e" instead of "46290_Aluminium,Magnesium" for example. No performance difference.

I'm running the same mongodb in my unix laptop and on a linux server instance. Version is 4.0.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.