3***@qq.com
3***@qq.com
  • 发布:2023-08-02 07:03
  • 更新:2023-08-02 11:18
  • 阅读:208

【报Bug】聚合操作 .addFields 里使用 $.first 等运算符报错

分类:uniCloud

产品分类: uniCloud/App

示例代码:

.group({
_id: '$orderId',
order: $.first('$order'),

        })  
        .sort({ "createdAt": -1 })  
        .addFields({  
            orderFrom: $.first("$order.orderFrom"),  

        })

操作步骤:

聚合操作

预期结果:

返回orderFrom

实际结果:

报错

bug描述:

聚合操作
.addFields 里使用 $.first 等运算符报错

code "InternalServerError"
message "Command failed with error 168 (InvalidPipelineOperator): 'Unrecognized expression '$first'' on server 172.28.207.10:3717. The full response is { \"operationTime\" : { \"$timestamp\" : { \"t\" : 1690930459, \"i\" : 2 } }, \"ok\" : 0.0, \"errmsg\" : \"Unrecognized expression '$first'\", \"code\" : 168, \"codeName\" : \"InvalidPipelineOperator\", \"$clusterTime\" : { \"clusterTime\" : { \"$timestamp\" : { \"t\" : 1690930459, \"i\" : 2 } }, \"signature\" : { \"hash\" : { \"$binary\" : \"jV4BF0YSVaqJDgrRp89xybS8SN8=\", \"$type\" : \"00\" }, \"keyId\" : { \"$numberLong\" : \"7239598038073737220\" } } } }"
stack "Error: Command failed with error 168 (InvalidPipelineOperator): 'Unrecognized expression '$first'' on server 172.28.207.10:3717. The full response is { \"operationTime\" : { \"$timestamp\" : { \"t\" : 1690930459, \"i\" : 2 } }, \"ok\" : 0.0, \"errmsg\" : \"Unrecognized expression '$first'\", \"code\" : 168, \"codeName\" : \"InvalidPipelineOperator\", \"$clusterTime\" : { \"clusterTime\" : { \"$timestamp\" : { \"t\" : 1690930459, \"i\" : 2 } }, \"signature\" : { \"hash\" : { \"$binary\" : \"jV4BF0YSVaqJDgrRp89xybS8SN8=\", \"$type\" : \"00\" }, \"keyId\" : { \"$numberLong\" : \"7239598038073737220\" } } } }\n at L.e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1611)\n at <anonymous>\n at process._tickCallback (internal/process/next_tick.js:189:7)"
2023-08-02 07:03 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ
  • 3***@qq.com (作者)

    你没搞明白吧, group 中 $.first('$order') 都正常运行了,说明$是声明了的。group 后的 addFields里面的$.first报错

    2023-08-02 13:10

  • DCloud_uniCloud_WYQ

    回复 3***@qq.com: first 只能在 group 阶段被使用,并且需要配合 sort 才有意义。

    2023-08-03 11:07

要回复问题请先登录注册