mongodb-js / mongoose-autopopulate

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

Remove execPopulate() to support Mongoose v6 #89

Closed botv closed 3 years ago

botv commented 3 years ago

Fixes #88. Please prioritize review, this library is heavily depended upon and needs to support the latest version of Mongoose. We've already moved our production codebase to a local version of the library due to this breakage, and anyone using the library for the first time will have this issue.

As explained in the v5 to v6 migration guide, execPopulate() is no longer a function. This plugin only uses execPopulate() in the post-save middleware, after chaining .populate() calls on the document instance. However, population chaining is no longer allowed on documents. The fix here was to use different population methods depending on context: in a query context, nothing changed. But for document context, we store all of the paths to populate in an array as we iterate over the schema paths, and then return the population promise at the end of the middleware.

Happy to make any changes, just let me know what to prioritize. Looping in @connorstevens and @ssudler who are happy to help as well.

vkarpov15 commented 3 years ago

Released mongoose-autopopulate 0.15.0 with support for Mongoose 6 :+1: