Mongoose populate sub-sub document

后端 未结 9 1949
深忆病人
深忆病人 2021-01-30 03:00

I have this setup in my MongoDB

Items:

title: String
comments: [] // of objectId\'s

Comments:

user: ObjectId()
item: Ob         


        
9条回答
  •  执笔经年
    2021-01-30 03:13

    I use this:

    .populate({
                path: 'pathName',
                populate: [
                    {
                        path: 'FirstSubPathName',
                        model: 'CorrespondingModel',
                    },
                    {
                        path: 'OtherSubPathName',
                        model: 'CorrespondingModel',
                    },
                    {
                        path: 'AnotherSubPathName',
                        model: 'CorrespondingModel',
                    },
                ]
            });
    

    it's the more easier way that i find to do this.I expect to help. :)

提交回复
热议问题