AppID:wx2805712f06257587
函数执行失败(耗时 5216ms) Error: collection.aggregate:fail -501001 resource system error. [FailedOperation.Timeout] Execution request timeout, Please check optimize your request(such as index), but if the problem persists, contact us.
按需建立索引,同时优化下查询索引,最后让这条聚合查询时间在3秒内,情况比较多,不一定是建了索引就立竿见影,具体只能您自己去优化了。官方的帖https://developers.weixin.qq.com/community/minihome/article/doc/0008cc5e8cc2a8d5789a981bf55c13
// 云函数入口文件 const cloud = require('wx-server-sdk'); const TcbRouter = require('tcb-router'); const getParams = (ctx) => { let params = ctx._req.event; delete params.$url; return params; }; const success = (data) => { return { status: 200, data, }; }; cloud.init({ env: 'release-4gh0j0n9669b023d', }); let db = cloud.database({ env: 'release-4gh0j0n9669b023d', }); const _ = db.command; // 云函数入口函数 exports.main = async (event, context) => { const app = new TcbRouter({ event, context, }); app.router('get_audit_list', getAuditList); return app.serve(); }; async function getAuditList(ctx, next) { const log = cloud.logger(); let params = getParams(ctx); let { page_no, page_size } = params; let skipCount = (page_no - 1) * page_size; let limitCount = page_size; let searchTask = await db .collection('uploadHistory') .aggregate() .lookup({ from: 'userInfo', localField: 'openid', foreignField: 'openid', as: 'userInfo', }) .match({ userInfo: { contact: 1, }, status: 0, }) .sort({ upload_time: -1, }) .skip(skipCount) .limit(limitCount) .end(); ctx.body = success(searchTask.list); }
你好,提供下环境ID,云函数代码,云函数名称,以及requestID。
云函数代码:我贴在下面回复了,
云函数名称:get_audit_list
requestID:ea773fc4-4929-11ec-a435-464512214622