当在$lookup连续使用pipeline的时候,即第三个表根据第二个表查出的role_id进行关联的时候,无法关联上,查询脚本如下
db.t_application_business.aggregate(
[{
“$lookup”: {
“from”: “t_user_application_business_role_permission”,
“let”: {
“main_business_id”: “$business_id”
},
“pipeline”: [{
“$match”: {
“$expr”: {
“$and”: [{
“$eq”: [“$business_id”, “$$main_business_id”]
}, {
“$eq”: [“$tenant_virtual_account”, {
“$literal”: “$v-2b2cfb7272f94bc590bc81245a39e56dasdasd”
}]
}, {
“$eq”: [“$status”, 0]
}, {
“$eq”: [“$delete_flag”, 0]
}]
}
}
}, {
“$project”: {
“tenant_virtual_account”: 1,
“role_id”: 1,
“application_id”: 1,
“create_time”: 1,
“status”: 1
}
}],
“as”: “businessRolePermission”
}
}, {
“$lookup”: {
“from”: “t_business_role”,
“let”: {
“main_role_id”: “$businessRolePermission.role_id”
},
“pipeline”: [{
“$match”: {
“$expr”: {
“$and”: [{
“$eq”: [“$role_id”, “$$main_role_id”]
}]
}
}
}],
“as”: “applicationBusinessRole”
}
}, {
“$match”: {
“seatBusinessRolePermission”: {
“$ne”: []
},
“seat_application_id”: {
“$in”: [“63299bd172f24fe18924598cd5695a1a”]
},
“status”: 0,
“delete_flag”: {
“$in”: [0]
}
}
}, {
“$project”: {
“business_name”: 1,
“business_id”: 1,
“businessRolePermission”: 1,
“applicationBusinessRole”: 1,
“create_time”: 1
}
}, {
“$sort”: {
“businessRolePermission.create_time”: 1
}
}, {
“$skip”: 0
}, {
“$limit”: 20
}]
)
921365915 编辑问题