mongodb-js / mongoose-autopopulate

Always populate() certain fields in your mongoose schemas
Apache License 2.0
221 stars 36 forks source link

Specify hooks where autopopulate should be triggered #84

Closed angelhodar closed 3 years ago

angelhodar commented 3 years ago

Hey, I just wanted to know if it is possible to specify only a subset of hooks where this plugin should be used. For example, I want this plugin to trigger after creating or updating a resource to return the populated response directly to the client, but I dont want to autopopulate when making a GET request as I already have implemented populate and select from URL query params. This would avoid to manually set { autopopulate : false } for that queries.

Thanks!

vkarpov15 commented 3 years ago

Just released 0.14.0 with a new feature for this, here's how to use it: https://github.com/mongodb-js/mongoose-autopopulate/blob/master/examples.md#it-can-pass-a-list-or-regular-expression-of-functions-to-apply-hooks-to