Skip to content
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

How to optimize a $match'less paginate query? #53

Open
vresetnikov opened this issue Apr 10, 2023 · 0 comments
Open

How to optimize a $match'less paginate query? #53

vresetnikov opened this issue Apr 10, 2023 · 0 comments

Comments

@vresetnikov
Copy link

Hello,

So the library allows to pass in an aggregation query that shapes the paginated results. One thing that I cannot seem to understand, is that since we are retrieving multiple unknown aggregated objects, the $match stage appears to be off the table. This makes more complex aggregation queries (such as the ones using $lookup stage very slow). For example:

Let's say I have products and containers collections. Products point to containers like so:

Product collection

{
_id: <mongo id>,
container: <container document id>,
<.. other product details>
}

Now, if I wanted to retrieve a specific container and $lookup its products, the query would be very fast because I could put $match in the beginning:

[MATCH container by container ID] [LOOKUP products that share the container id] [PROJECT]

However, with mongoose-aggregate-paginate-v2, I am now retrieving multiple resources, so the MATCH stage is lost, making the LOOKUP very slow?

Is there a way to counter this? What should I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant