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

Bug: .populated within an array seems inconsistent. #8247

Closed
dave-continuum-media opened this issue Oct 14, 2019 · 0 comments
Closed

Bug: .populated within an array seems inconsistent. #8247

dave-continuum-media opened this issue Oct 14, 2019 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@dave-continuum-media
Copy link

dave-continuum-media commented Oct 14, 2019

What is the current behavior?

A model containing an array of another schema, which itself has a reference to another model. When calling .populated('nested.reference') the result doesn't appear to match the length of the array if you have pushed new items into the array.

https://gist.github.com/dave-continuum-media/09848138ae86508d891c65bddc537b20

What is the expected behavior?

.populated('nested.reference') should return undefined if none of the items are populated but an array of equal length to the sub-schema array if some or all are.

Currently it takes extra effort to tell if a document subschema array has been fully populated:

const populated = doc.populated('nested.reference');
if (populated === undefined || populated.length < doc.nested.length) {
    await doc.populate('nested.reference');
}
@vkarpov15 vkarpov15 added this to the 5.7.6 milestone Oct 17, 2019
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Oct 17, 2019
vkarpov15 added a commit that referenced this issue Oct 20, 2019
vkarpov15 added a commit that referenced this issue Oct 20, 2019
vkarpov15 added a commit that referenced this issue Oct 21, 2019
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

No branches or pull requests

2 participants