[图片]聚合里面这个换成$
group分组查询后,筛选时报错?代码如下:想查询num大于1的数据 return db.collection('amount').aggregate() .group({ _id: '$openid', num: $.sum(1) }) .match({num:_.gt(1)}) .end() .then((result)=>{ console.log(result) }) 报错如下: {"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: collection.aggregate:fail -502001 database request fail. [FailedOperation] Failed operation. Please check your request, but if the problem persists, contact us.\n at Object.toSDKError (/var/user/node_modules/wx-server-sdk/index.js:8094:19)\n at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1422:23)\n at Promise (/var/user/node_modules/wx-server-sdk/index.js:1161:33)\n at process._tickCallback (internal/process/next_tick.js:68:7)","statusCode":430}
2022-05-31[图片]这边应该是 return ddRes 吧,赋值是啥意思
云开发中,出现504002错误,该怎么解决?基础库 2.22.0 刚开始运行可以,后来不知道为什么,就提示错误了,请大神指点一下。云函数代码如下: 错误代码在下面。 // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) const db = cloud.database({ throwOnNotFound: false, }) const _ = db.command const $ = _.aggregate // 云函数入口函数 exports.main = async (event) => { /** * 先读取车轮战数据库中,对应game_id的记录 * 再比对/时间、状态、参加与否 * 然后在找到的记录中,提取一个,写入mh_id,改变状态, */ try { const transaction = await db.startTransaction() //启动事务 const aaaRes = await transaction.collection('mh_game_chelunzhan') .aggregate() //聚合数据 的方式进行筛选 .match({ zhuangtai: event.zhuangtai, //1-房间等待,2-战斗中,3-自由匹配,4-退出 game_id: event.game_id, //查找本游戏的ID mhID_1: _.neq(event.mhID), //在mhID_1和mhID_2里,没有自己mhIDr值的 mhID_2: _.neq(event.mhID) }) .sample({ //聚合中随机选了N条记录 size: 1 }) .end() const cccRes = await aaaRes.list[0]._id //将ID赋值给cccRes let dddRes = '' //设置dddRes常量 const bbbRes = await transaction.collection('mh_game_chelunzhan') // const bbbRes = await db.collection('mh_game_chelunzhan') //更新记录 .doc(cccRes) .update({ data: { zhuangtai: 2, //1-房间等待,2-战斗中,3-自由匹配,4-退出 mhID_2: event.mhID } }) .then({ dddRes = cccRes }) return { // this1: aaaRes, // this2: bbbRes, this3: dddRes // aaa:'123' } } catch (e) { console.error('transaction error', e) return { success: false, error: e } } } 错误提示如下: WASubContext.js?t=wechat&s=1644366092828&v=2.22.0:2 Unhandled promise rejection Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Runtime.UserCodeSyntaxError: SyntaxError: Invalid shorthand property initializer at Object.module.exports.load (:16998/var/runtime/node12/UserFunction.js:32) at Runtime.handleOnce (:16998/var/runtime/node12/Runtime.engine.js:99) at Timeout._onTimeout (:16998/var/runtime/node12/Runtime.engine.js:56) at listOnTimeout (:16998/appservice/internal/timers.js:549) at processTimers (:16998/appservice/internal/timers.js:492) (callId: 1644371825870-0.3668426811601977) (trace: 9:57:5 start->9:57:6 system error (Error: errCode: -504002 functions execute fail | errMsg: Runtime.UserCodeSyntaxError: SyntaxError: Invalid shorthand property initializer at Object.module.exports.load (:16998/var/runtime/node12/UserFunction.js:32) at Runtime.handleOnce (:16998/var/runtime/node12/Runtime.engine.js:99) at Timeout._onTimeout (:16998/var/runtime/node12/Runtime.engine.js:56) at listOnTimeout (:16998/appservice/internal/timers.js:549) at processTimers (:16998/appservice/internal/timers.js:492)), abort) at C (WASubContext.js?t=wechat&s=1644366092828&v=2.22.0:2) at WASubContext.js?t=wechat&s=1644366092828&v=2.22.0:2 at WASubContext.js?t=wechat&s=1644366092828&v=2.22.0:2 at n (WASubContext.js?t=wechat&s=1644366092828&v=2.22.0:2)(env: Windows,mp,1.05.2201240; lib: 2.22.0)
2022-02-10兄弟,有没解决
云开发Web SDK init失败,提示需要先调用wx.cloud.init?Web SDK init失败,提示需要wx.cloud.init [图片] [图片] [图片]
2020-09-05