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

Using $facet instead of two queries & adding paginateExec to Aggregate #36

Merged
merged 4 commits into from
May 21, 2021

Conversation

claude-abounegm
Copy link
Contributor

@claude-abounegm claude-abounegm commented May 21, 2021

This pull request contains two features:

  • $facet operator is now being used by default instead of executing two queries. To disable, pass useFacet: false to the options.
  • Mongoose's Aggregate is extended and paginate can now be called directly using aggregate.paginateExec(options, [cb]).

If countQuery and useFacet, two queries will still be executed, and facet will be ignored.

Breaking Changes:

  • $facet and $count require mongo 3.4+
  • $facet is now used by default.

@claude-abounegm claude-abounegm changed the title Adding option to use $facet instead of two queries Using $facet instead of two queries & adding paginateExec to Aggregate May 21, 2021
@aravindnc
Copy link
Owner

@claude-abounegm Much thanks.

@aravindnc aravindnc merged commit 772b669 into aravindnc:master May 21, 2021
@aravindnc
Copy link
Owner

@claude-abounegm Can you add a test case too.

@claude-abounegm
Copy link
Contributor Author

@aravindnc will do soon!

@saminndex
Copy link

saminndex commented Jul 4, 2024

FYI there's a breaking change that's not mentioned which means you cannot use $geoNear queries when useFacet is set to true with the error message $geoNear is not allowed to be used within a $facet stage so if you're using this in your aggregatepaginate query using the mongoose-aggregate-paginate-v2 package, you'll need to set this to false. Further reading: https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/

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

Successfully merging this pull request may close these issues.

3 participants