Skip to content

Add FAQ about slow joins #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ FAQ

This page contains a list of some frequently asked questions.

Performance
===========

Querying across relational fields like :class:`~django.db.models.ForeignKey` and :class:`~django.db.models.ManyToManyField` is really slow. Is there a way to improve the speed of these joins?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Not really. Joins use MongoDB's :doc:`$lookup
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: "Not really."

We could mention the possibility of using raw_aggregate() to manually construct a query as mentioned in #309, but I think that's unlikely to be an attractive and maintainable solution for most projects.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 we could, the people then will ask: why aren't you doing that approach?
The answer is: because we have to modify the django query tree or handle this particular case differently. IMO keep this as it is now, otherwise we should explain the limitations that we have in this particular case.

<manual:reference/operator/aggregation/lookup>` operator, which doesn't perform
well with large tables.

The best practice for modeling relational data in MongoDB is to instead use
:doc:`embedded models <topics/embedded-models>`.

Troubleshooting
===============

Expand Down
Loading