Slow request response

Hello, I have some problems with queries to the collection of users, there are more than 130 thousand documents in it, and when I want to get the data of the (findOne) user, it takes time, and therefore the bot gives with a slight delay, which I do not like. How can this problem be corrected?

Hi @Ivan_Ermolaev ,

Welcome to MongoDB community

Is the filter of findOne query indexed?

Can you provide explain(true) of that query to review the plan?

Thanks
Pavel

I use mongoose as request processing, here is an example document from the collection of users and a request to this document.
webstorm64_bpllpUwY8v

Hi @Ivan_Ermolaev ,

To assist you I need the query and the . explain (true) run from a mongo shell

This will show the chosen plan to execute the query and plan …

If you cannot provide a query please provide the code.

Thanks
Pavel

If I understand you correctly, this is what I got. I apologize if I’m stupid somewhere, because I haven’t quite figured it out in mongodb yet

Hi @Ivan_Ermolaev ,

This is not a findOne query but a full find returning 134k documents in 80ms which is more than reasonable…

Are you sure this is the issue you are experiencing as I don’t see an issue here.

I would expect something like

db.users.findOne({userId : ...})

And the userId is indexed.

Thanks
Pavel

Hello, @Pavel_Duchovny,
came back with an answer. Here is a check of the request for a specific filter and the response received.
I was just told that there is a called collection type, can it be slow to respond to requests because of this type?

Hi @Ivan_Ermolaev ,

Those fields are not indexed and therefore a collection scan is performed which is highly suboptimal.

Please index { guiID : 1, userID : 1} and this will run much faster.

I see there is only one index which is default _id. Please see the following blog to index your other queries properly

Thanks
Pavel

Hi, @Pavel_Duchovny ,
Wow, that really helped! Thank you for your help!

1 Like