11月1日补充,以下问题仅出现在JQL中,若在云函数中使用uniCloud.database()获取db执行,则返回正常,与腾讯云开发表现一致。
如题,$.add返回形如:{command:value},$.subtract返回却是值。(以下测试在JQL调试器中)
实例如下:
test表只有一条数据:
{
"id": "5d352be5558b81140fe3c141",
"content": "test",
"as": []
}
查询语句如下:
db.collection("test")
.aggregate()
.addFields({
a: $.cond([$.isArray("$as"), $.size("$as"), 0]),
})
.addFields({
n: $.add(["$a", 1])
})
.end()
结果如下:
[
{
"_id": "635a3ad4737e2800019fea54",
"a": 0,
"as": [
],
"content": "test",
"id": "5d352be5558b81140fe3c141",
"n": {
"command": 1
}
}
]
若是使用$.subtract,则为:
[
{
"_id": "635a3ad4737e2800019fea54",
"a": 0,
"as": [
],
"content": "test",
"id": "5d352be5558b81140fe3c141",
"n": -1
}
]
除了上述问题外,这个查询语句在客户端或云函数中使用uniCloud.databseForJQL获取db调用时会报错如下:
InternalServerError: errCode: InternalServerError | errMsg: Command failed with error 40180 (Location40180): 'Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path n' on server 192.168.146.109:3717. The full response is { "operationTime" : { "$timestamp" : { "t" : 1666885450, "i" : 16 } }, "ok" : 0.0, "errmsg" : "Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path n", "code" : 40180, "codeName" : "Location40180", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1666885450, "i" : 16 } }, "signature" : { "hash" : { "$binary" : "2ggBcFxRNhaYiNAPEKLVvLvBHn4=", "$type" : "00" }, "keyId" : { "$numberLong" : "7124964235662065714" } } } }
2 个回复
魑魅魍魉cmwl (作者)
目前采用的临时解决方案如下:
采用$.subtract与负数作差
DCloud_uniCloud_WYQ
Bug已确认,感谢反馈