I have an web app that is connected to a database with approx 10000 documents (about 30mb) on a M2 instance. Each document have 35 fields of which 4 are array fields. 3 array fields for numbers, where the biggest array has 168 elements, and 1 array with mixed data types. In my world this constitute a small database with little data.
The problem I have is that simple queries where I include the array fields take a lot of time to return. Note that I do not do any sorting or anything on those arrays. With out the array fields a typical query I make takes about 300ms to return. For each array field I include it adds about one second(!) to the query, and if I include all 4 the query takes about 4-5 seconds to return.
What is also very odd, is that from time to time, there is no slow down when I add the array fields. Then it stays like that for some hours or a day, then it goes back backing super slow again. This affects both my production code and my development code at the same time. According to MongoCompass the query is lightning fast, as I imagine it should be. But in reality it is not.
Any suggestion what could be wrong?
I am using node, express, and mongoose.