k***@163.com
k***@163.com
  • 发布:2023-03-27 01:02
  • 更新:2023-03-27 16:18
  • 阅读:138

数据库联表查询 pipeline 问题

分类:uniCloud

有这个需求,uni-id-use 为主表,order为副表。

let userOrder = await db.collection('uni-id-users')
.aggregate()
lookup({
from: "orders",
let: {
user_id: '$_id' // 定义主表变量,$_id是主表字段
},
pipeline: $.pipeline()
.match(
$cmd.expr($.and([
$.eq(['$userid', '$$user_id']), // $userid 是副标字段
$.gte(['$creat_date', begin_time]), $.lte(['$creat_date', end_time]) // 根据订单时间段查询
])))
.project({
_id: 0,
orderNo: 1, // 自定义订单编号
money: 1, // 订单金额
creat_date: 1 // 下单日期
})
.done(),
as: 'orders_list'
})
.project({ //关联别名
'mobile': true,
'orders_list.orderNo': true,
'orders_list.money': true,
'orders_list.creat_date': true,
'money_total': $.sum([
"$orders_list.money"
]),
quantity: true
})
.limit(rows)
.skip(page)
.end();

现在有这个问题,如果是新用户从未下单,那么返回的列表是这样

data:{
list:[
{
_id:"641ff0dd28064a03b784d5f6",// 用户id
mobile:"xxxxxxxxx",
money_total:0,
order_list:[],
}
]
}

在match中如何判断订单为空的情况list中就不显示这个用户数据? 求大神指点

2023-03-27 01:02 负责人:无 分享
已邀请:
k***@163.com

k***@163.com (作者)

有人知道吗

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

k***@163.com

k***@163.com (作者)

好的,非常感谢

要回复问题请先登录注册