Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

mongoose怎么遍历array类型的字段populate到一个属性中

有一个集合是这样的额

用户集合

{
    name:‘小明’,
    age:18,
    pets:['111','222']  //这里面存宠物集合的id
}

宠物集合

[
    {
    _id:'111',
    name:'大黄'
},
{
    _id:'222',
    name:'旺财'
},
    
]

怎么去填充到一个pets里面 把属于的小明的宠物都填充到返回的pets字段里面,求解

{
name:‘小明’,
pets:[
{name:'大黄'},
{name:'旺财'},
]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...