MongoDB lookup is slow

Hi,

I have two collections. One with product details

{
product_id:…,
product_name:…
}

and another with product components

{
product_id:…,
component_name:…,

}

with one-to-many relationship. One product can have many product components. When I do a query with lookup it is too slow. I am just trying to retrieve 1000 documents from 3000. Do I have to add any index?

yes, having the appropriate indices is the first step to have decent performance with any system.

the other step is to have sufficient hardware for your use cases, that means enough RAM, CPU and permanent storage

Your product component collection must absolutely have an index on the field by which you are doing the $lookup (most likely that’s product_id?). If you provide the actual pipeline that’s slow along with what version, etc you are running we might be able to help further.

Asya

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.