exports.main = async (context) => {
return await context.cloud.db.collection('t_lottery_code_user').aggregate([
{
$match: { aid:"5fe1af34ef507173a3ac67ac",status:1}
},
{
$lookup:{
from:'t_lottery_code_access',
let:{aid:"$aid",openId:"$openId"},
pipeline:[
{
$match:
{
$expr:
{
$and:[
{ $eq: ["$aid", "$$aid"] },
{ $eq: ["$openId", "$$openId"] }
]
}
}
},
],
as:"aa"
}
},
{
$unwind: '$aa',
},
{
$match: {
"aa.lotteryCode.status": 1
}
},
{
$project:{
_id:0,
aid:1,
userNick:1,
code:"$aa.lotteryCode.code",
status: "$aa.lotteryCode.status",
beiz:"$aa.beiz"
}
},
]);
}
返回数据格式:
![f309bdbca3ee8c561ae690f38e9026f7.png](https://i-blog.csdnimg.cn/blog_migrate/bf759430c712520b3c15f08346eaf166.jpeg)