【问题标题】:Mongoose populate within populated arrayMongoose 在填充数组中填充
【发布时间】:2019-07-28 12:57:32
【问题描述】:

所以如果我执行以下操作:

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": "tobi@gmail.com",
                    "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】:

    发帖后马上解决

    .populate({ path: 'chat_list.participants', populate: { path: 'profile' } })
    

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 2014-12-05
      • 2019-03-28
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2022-01-24
      相关资源
      最近更新 更多