Skip to content

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

@dave-continuum-media

Description

@dave-continuum-media

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');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions