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

Mongoose 6: Deep-populate with string causing errors (undocumented breaking change?) #11160

Closed
hansemannn opened this issue Dec 30, 2021 · 3 comments · Fixed by #11168
Closed
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@hansemannn
Copy link
Contributor

I'm not sure if this may be documented as a breaking change somewhere, but I couldn't find it: When using a string-based populate, it fails with Mongoose 6 while it works with 5.x:

await MyModel.findById(myId).populate({ path: 'subModel', populate: 'subField' });

The same works with brackets:

await MyModel.findById(myId).populate({ path: 'subModel', populate: ['subField'] });

It's fine to migrate, but devs may not know it's an issue until they run a related query.

@hansemannn hansemannn changed the title Mongoose 6: Deep-populate with string causing errors Mongoose 6: Deep-populate with string causing errors (undocumented breaking change?) Dec 30, 2021
@IslandRhythms IslandRhythms added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Dec 30, 2021
@IslandRhythms
Copy link
Collaborator

IslandRhythms commented Dec 30, 2021

I'm reading the docs and I don't see a populate option in the populate function. What does the populate option do?
From what I'm reading on your example code, do you mean for populate to be model? so path: 'subField', model: 'subModel'?

@mjfwebb
Copy link

mjfwebb commented Dec 31, 2021

I believe the changes are part of this note https://mongoosejs.com/docs/migrating_to_6.html#removed-execpopulate

The note itself is poorly written. As you say there were more changes made to the way the populate method was changed than just execPopulate being removed: chaining .populate calls was replaced by an array of populate paths. The same is true for nested populate paths like what you're attempting to do.

@hansemannn
Copy link
Contributor Author

This is possible! If helpful, I can update the docs and draft a PR for it.

AbdelrahmanHafez added a commit to AbdelrahmanHafez/mongoose that referenced this issue Jan 3, 2022
@AbdelrahmanHafez AbdelrahmanHafez added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Jan 3, 2022
@AbdelrahmanHafez AbdelrahmanHafez added this to the 6.1.5 milestone Jan 3, 2022
vkarpov15 added a commit that referenced this issue Jan 4, 2022
fix(document): allow populating deeply nested models as strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants