我想加入收藏。以前,我只使用查找,这样我就可以得到连接的分离字段。但我需要得到类似 mysql join 的结果。我注意到此操作有 $lookup 和 $mergeObjects 但效果不佳。
用户收集模型。
{
"_id": ObjectId("xxxxxxx"), //this is default id from mongoDB
"name": 'admin user',
"email": 'admin@test.com',
"password": 'xxxxxxxx',
"roles": [
{
"id": 0,
"approved": true
},{
"id": 2,
"approved": true
}
]
},{
"_id": ObjectId("xxxxxxx"), //this is default id from mongoDB
"name": 'userOne',
"email": 'user@test.com',
"password": 'xxxxxxxx',
"roles": [
{
"id": 1,
"approved": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
角色集合模型。
{
"_id": ObjectId("xxxxxxx"), //this is default id from mongoDB
"id": '0',
"name": 'administrator'
},{
"_id": …Run Code Online (Sandbox Code Playgroud) javascript mongodb node.js mongodb-query aggregation-framework