云数据库用$.in查询数组字段怎么写?
发布于 6 年前 作者 guiyingtan 4288 次浏览 来自 问答

云函数里希望查询一个数组字段是否包含一个值,用了$.in(因为还需要用到了其他aggregate函数,所以这里选用aggregate函数 $.in)

await db.collection('products').where(_.expr(
        $.in(['xx', '$supplierId'])
      )).update({
      data: {
        status: 0
      }
    })

报错如下,似乎不认数组型字段作为第二个数组参数

日志内容 Request ID: 37244d0c-60a2-11ea-98ea-5254006250a6
执行时间: 100ms内存使用: 36.38 MB
返回结果
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{$in requires an array as a second argument, found: missing}]}, {\u003cnil\u003e}]; \nError: errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{$in requires an array as a second argument, found: missing}]}, {\u003cnil\u003e}]; \n    at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6086:16)\n    at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1397:23)\n    at Promise (/var/user/node_modules/wx-server-sdk/index.js:1489:33)\n    at \u003canonymous\u003e\n    at process._tickCallback (internal/process/next_tick.js:188:7)"}
日志
START RequestId: 37244d0c-60a2-11ea-98ea-5254006250a6
Event RequestId: 37244d0c-60a2-11ea-98ea-5254006250a6
Error: errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{$in requires an array as a second argument, found: missing}]}, {<nil>}]; 
    at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6086:16)
    at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1397:23)
    at Promise (/var/user/node_modules/wx-server-sdk/index.js:1489:33)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) 
ERROR RequestId:37244d0c-60a2-11ea-98ea-5254006250a6 Result:{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{$in requires an array as a second argument, found: missing}]}, {\u003cnil\u003e}]; \nError: errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{$in requires an array as a second argument, found: missing}]}, {\u003cnil\u003e}]; \n    at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6086:16)\n    at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1397:23)\n    at Promise (/var/user/node_modules/wx-server-sdk/index.js:1489:33)\n    at \u003canonymous\u003e\n    at process._tickCallback (internal/process/next_tick.js:188:7)"} 
 
END RequestId: 37244d0c-60a2-11ea-98ea-5254006250a6
Report RequestId: 37244d0c-60a2-11ea-98ea-5254006250a6 Duration:100ms Memory:256MB MemUsage:36.378906MB
腾讯云TCB提供存储及计算服务
2
true, suggestion, has details (occurred 2 times)

回到顶部