Skip to content

[BUG] populate not working in nested array #797

@a-azad-developer

Description

@a-azad-developer

I have a model "accounts" with a users array, userId in users items referred to the users model.
but when I want to get a list of accounts or findOne, I can't get the user document by populate


const schema = new Schema(
    {
       ...
     
        owner: { type: Schema.Types.Reference, ref: "users" }, // Reference to Users (works),
        users: [
            {
                userId: { type: Schema.Types.Reference, ref: "users" }, // Reference to Users (not works)
                ...
            }

this my find service:

 accountsModel.find(filters, {
      
        populate: {
            owner: ["firstName", "lastName", "email", "type", "id"],
            users :{
populate: { 
      userId: ["status", "id", "firstName", "lastName", "email", "type"],
}
        },
        populateMaxDeep: 3,
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions