Mongodb左连接-aggregate聚合函数查询
程序员文章站
2022-05-08 16:09:38
...
目标数据
源数据
表名:Address
相对于传统数据库写法
select ad._id as adId,ad.name,o.h,o.w
from adress as ad
left join order as o on o._id=ad.aId;
mongodb-aggregate左连接写法
db.address.aggregate([
{$unwind:{
path:"$order",
preserveNullAndEmptyArrays:true}
},
{$project:{
_id:1,
name:1,
h:"$order.h",
w:"$order.w",
uom:"$order.uom"
}
}
]);