Mongoose填充在填充的数组中

问题描述 投票:0回答:1

所以,如果我执行以下内容:

Chat.findOne({ user: req.user._id })
        .populate({ path: 'chat_list.participants' })
        .then((chat) => {
            res.json(chat);
        })

输出如下:

{
    "_id": "5c7ff03f8ae0be31a0b7002f",
    "chat_list": [
        {
            "participants": [
                {
                    "securityQuestions": {
                        "isSetup": false
                    },
                    "videos": [],
                    "events": [],
                    "_id": "5c7d66065619c542e81583c6",
                    "name": "Tobi Uchiha",
                    "email": "[email protected]",
                    "date": "2019-03-04T17:53:10.267Z",
                    "__v": 0,
                    "profile": "5c7d66065619c542e81583ca",
                    "profile_type": "PartnerAdminProfile"
                }
            ],
            "messages": [],
            "_id": "5c800d7997f7d74bacade2a6"
        }
    ],
    "user": "5c7f36d7e7a5c04e5046e8ca",
    "chat_history": [],
    "__v": 0
}

我也试图填充个人资料。但是,如果我做这样的事情.populate({path:'chat_list.participants.profile'})它只是拯救了。如何在填充的参与者数组中填充嵌套的配置文件?

mongoose
1个回答
0
投票

Welp在发布后立即解决了这个问题

.populate({ path: 'chat_list.participants', populate: { path: 'profile' } })
© www.soinside.com 2019 - 2024. All rights reserved.