{
"errCode": -404011,
"errMsg": "Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID ed4445d2-e228-11ea-8d19-525400fbcc42, cloud function service error code -504002, error message ReferenceError: phone is not defined\n at Runtime.exports.main [as handler] (/var/user/index.js:21:35)\n at Runtime.handleOnce (/var/runtime/node10/Runtime.engine.js:213:23)\n at Timeout.setTimeout [as _onTimeout] (/var/runtime/node10/Runtime.engine.js:54:12)\n at ontimeout (timers.js:436:11)\n at tryOnTimeout (timers.js:300:5)\n at listOnTimeout (timers.js:263:5)\n at Timer.processTimers (timers.js:223:10); at cloud.callFunction api; "
}
这里面的 phone是我的数据库,主要是用来模糊查询(字符串),不知道哪里有问题
云函数部署了么?最好还是亮代码。
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
const MAX_LIMIT = 100
// 云函数入口函数
exports.main = async (event, context) => {
const countResult = await db.collection(database19).count()
const total = countResult.total
// 计算需分几次取
const batchTimes = Math.ceil(total / 100)
// 承载所有读操作的 promise 的数组
const tasks = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection(database19).where({
name: db.RegExp({
regexp: '.*' + '思科'})
}).skip(i * MAX_LIMIT).limit(MAX_LIMIT).get({
success: console.log,
fail: console.error
})
console.log(tasks)
tasks.push(promise)
}
// 等待所有
return(await Promise.all(tasks)).reduce((acc, cur) => {
return {
data: acc.data.concat(cur.data),
errMsg: acc.errMsg,
}
})
}
和之前一样,总是显示集合没有定义,但是我明明上传了,云函数也部署了,环境也配置了
进行分页操作,每页显示100条。task[0]就是0~99的数据,task[1]就是100~199的数据。
你照搬肯定不行,最少你要操作哪个数据库集合你总得定义吧!手动汗(⊙﹏⊙)b