支付宝云使用uni-app聚合联表查询 pipeline内不支持$.filter写法格式 阿里云没有问题

支付宝云使用uni-app聚合联表查询 pipeline内不支持$.filter写法格式 阿里云没有问题

操作步骤:

  • 按照提示代码进行复现

预期结果:

  • 可以使用filter进行数组过滤

实际结果:

  • 聚合内不支持$.filter,导致查询出的结果为null

bug描述:

async demo(status=1){  
    let res = await dbJQL.collection("JLJ-pay-orders").aggregate()  
        .match(`order_status == ${status}`)  
        .unwind('$goods_list') // 展开goods_list数组  
        .lookup({  
            from: "JLJ-mall-goods",  
            let: {  
                goods_id: '$goods_list.goods_id',  
                sku_id: '$goods_list.sku_id'  
            },  
            pipeline: $.pipeline()  
                .match(dbCmd.expr($.eq(['$_id', '$$goods_id'])))  
                .project({  
                    name: 1,  
                    sku: $.filter({  
                      input: '$sku',  
                      as: 'item',  
                      cond: $.eq(['$$item._id', '$$sku_id'])  
                    })                        
                })                    
                .done(),  
            as: "goodsInfo"  
        })  
        .sample({  
            size: 5  
        })  
        .skip(1)  
        .end()  

        return res;  
}

上面写法格式,想要对字段进行过滤,但是支付宝云不支持数据库运算方法,不支持$.filter,导致查询出的结果为null


更多关于支付宝云使用uni-app聚合联表查询 pipeline内不支持$.filter写法格式 阿里云没有问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

我反馈一下。

更多关于支付宝云使用uni-app聚合联表查询 pipeline内不支持$.filter写法格式 阿里云没有问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html


关于支付宝云不支持$.filter的问题分析

这是一个支付宝云JQL聚合查询中$.filter语法支持的问题。从代码来看,您正在尝试在pipeline中使用$.filter来过滤sku数组,但支付宝云目前确实不支持这种写法。

问题原因

支付宝云的JQL实现与阿里云存在差异,特别是在聚合查询的pipeline中,部分操作符(如$.filter)尚未支持。这导致了查询结果返回null。

临时解决方案

您可以考虑以下替代方案:

  1. 使用project+map替代filter
.project({
    name: 1,
    sku: $.map({
        input: '$sku',
        as: 'item',
        in: $.cond(
            [$.eq(['$$item._id', '$$sku_id'])],
            '$$item',
            null
        )
    })
})
回到顶部