room集合内数据
[{
_id:123,
_openid:123,
members:["_openid1","_openid2","_openid3"]
name:"包房"
}]
user集合内数据
[
{
_id:222,
_openid:"_openid1",
name:"zahngsan"
},{
_id:333,
_openid:"_openid2",
name:"lisi"
},{
_id:444,
_openid:"_openid3",
name:"wangwu"
},
]
我想要拿到 room集合 内数据,并关联 members字段 到 user集合
我想得到的数据结构
[{
_id:123,
_openid:123,
name:"包房"
members:[
{
_id:222,
_openid:"_openid1",
name:"zahngsan"
},{
_id:333,
_openid:"_openid2",
name:"lisi"
},{
_id:444,
_openid:"_openid3",
name:"wangwu"
},
],
}]
这个应该怎么写,求大佬帮帮忙
db.collection('room') .aggregate() .lookup({ from:'user', localField:'members', foreignField:'_openid', as:'members' }) .end()