2 / 3
Oct 2024

I have a simple collection and a simple query. I got that it takes very long time like 45-60 seconds. I tried to understand what is going on.

When the query is like findOne({usernames:'someuser'}) that takes 4-5 seconds. But only find() takes 45 seconds. I imported the same data into the local mongodb server and it doesnt even take 1 second. (Nodejs Express server + Mongoose also I tried same for Mongo NAtive dirver)

I check logs on remote server but there is nothing specific and nothing shows any log that implies query could be some slow. Mongo server runs on docker, version is 4.4. and I upgraded to 5 and still nothing changed.

I checked memory and cpu usages, cpu is not even 1%, and mem usage is not even 20%. It is not a busy server, no specific big data.

I open mongo shell and the result comes in 7-8 seconds.

So what is happening? What should I do to understand what is going on? setLogLevel(5) many logs but nothing like error

I turns out that probably it it a network issue on docker. I open studio 3T and I got same response approx 45 seconds but on terminal same query returns immediately. Now I dont know what to do. Is tehre anything on docker network I can do?

How many documents do you have in your collection?

What indexes do you have?

What do you do with the find() results? How do you determine the 45 seconds?