Hi Ilyas, and welcome to the MongoDB forums! :slight_smile:

Without taking a look at your data schema and indexes, it’s really hard to give you an exact answer. There are some things that you can try, though.

The first step would be to try to better understand why the query is slow. You can find more about your query performance by using an explain. I’ve found that this docs page can be very useful in understanding the explain results.

If you’re using MongoDB Atlas, or MongoDB OpsManager, you could also try to take a look at the MongoDB Performance Advisor that can provide you with tips on how to increase the general performance of your cluster.

Often times, slow queries can be fixed with indexing. If you are using MongoDB Atlas, you can take a look at this tutorial for more tips and tricks about how to optimize query performance.

Finally, performance issues can sometimes be dealt by optimizing your data schema with some of the data modeling patterns. If you have many $lookup stages or computation in your queries, consider using patterns such as the Extended Reference pattern, or the Computed pattern. You can find great courses on data modeling in MongoDB University.

I hope this will help you find the best solution for your use case!
-Joel

2 Likes