哪位大神帮忙解答下。
jql联表查询的时候,结果显示去重了。
详情如下:
订单表里有一行数据。
{
"_id": "654bce482139297f8b281f1f"
// 这里是商品详情,如商品的标题
"goodsId": [ "652917e455b3379a662d3049","65291c679755e363d7b8d675", "65291a406523417a8a275aed"],
// 这里是商品的规格,如,颜色,尺寸
"goodsSkuId": ["652f9b45a09a9bd1a4d0c029","652f9b45a09a9bd1a4d0c029",""]
}
联表查询如下:
let order= uniCloud.databaseForJQL().collection("order")
.field("goodsId,goodsSkuId")
.getTemp()
let goods = uniCloud.databaseForJQL().collection("goods")
.field("_id,title,price")
.getTemp()
let goodsSku = uniCloud.databaseForJQL().collection("goodsSku")
.field("_id,title")
.getTemp()
uniCloud.databaseForJQL().collection(order,goods,goodsSku)
.get()
.then(res=>{
console.log(res.data)
})
结果如下:我并没有使用.distinct()去重,结果仍然去重了。大概原因是goodsSkuId一模一样吧,都是共用的"652f9b45a09a9bd1a4d0c029"这个值,而且goodsSkuId的第三个空值也省略了。
[
{
"_id": "654bce482139297f8b281f1f"
"goodsId": [
{
"price": 579900,
"_id": "652917e455b3379a662d3049",
"title": "Apple iPhone 15 (A3092) 128GB 粉色 支持移动联通电信5G 双卡双待手机"
},
{
"price": 579900,
"_id": "65291c679755e363d7b8d675",
"title": "Apple iPhone 15 (A3092) 256GB 粉色 支持移动联通电信5G 双卡双待手机"
},
{
"price": 529900,
"_id": "65291a406523417a8a275aed",
"title": "华为/HUAWEI Mate 60 12GB+512GB 雅川青 旗舰手机"
}
],
"goodsSkuId": [
{
"_id": "652f9b45a09a9bd1a4d0c029",
"title": "粉色"
}
]
}
]
我希望的结果如下,希望各位大佬教下该怎么修改,文档里实在没写这块。
[
{
"_id": "654bce482139297f8b281f1f"
"goodsId": [
{
"price": 579900,
"_id": "652917e455b3379a662d3049",
"title": "Apple iPhone 15 (A3092) 128GB 粉色 支持移动联通电信5G 双卡双待手机"
},
{
"price": 579900,
"_id": "65291c679755e363d7b8d675",
"title": "Apple iPhone 15 (A3092) 256GB 粉色 支持移动联通电信5G 双卡双待手机"
},
{
"price": 529900,
"_id": "65291a406523417a8a275aed",
"title": "华为/HUAWEI Mate 60 12GB+512GB 雅川青 旗舰手机"
}
],
"goodsSkuId": [
{
"_id": "652f9b45a09a9bd1a4d0c029",
"title": "粉色"
},
{
"_id": "652f9b45a09a9bd1a4d0c029",
"title": "粉色"
},
{}
// 或者
{"_id": "","title": ""},
]
}
]
深圳奥飞网络 (作者)
谢谢告知。感谢
2023-11-09 21:13