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

Ability to autopopulate with aggregation queries #47

Closed
chaddjohnson opened this issue Oct 18, 2018 · 2 comments
Closed

Ability to autopopulate with aggregation queries #47

chaddjohnson opened this issue Oct 18, 2018 · 2 comments

Comments

@chaddjohnson
Copy link

Hi! Thanks for the great plugin.

I'd like to suggest autopopulation with aggregation queries. When I do an aggregate query, autopopulation does not seem to occur.

@vkarpov15
Copy link
Member

@chaddjohnson that's by design right now. MongoDB aggregation can modify the shape of the document, so in general the output of the aggregation won't match the model's schema, so autopopulate won't work reliably. What are you trying to achieve with autopopulate for aggregations?

@chaddjohnson
Copy link
Author

Ah, that is true and makes sense.

I was trying to select a random document from a collection using $sample which required use of aggregation. But I found a different (faster) approach which involves querying for a count and then using .find() and skipping a random number of documents.

Thanks for responding. I no longer have a strong use case for auto-population with aggregate queries.

Also, thanks so much for the autopopulate and for Mongoose. So super useful they are, and perfect.

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

2 participants