const db = wx.cloud.database()
const MAX_LIMIT = 100
exports.main = async (event, context) => {
const countResult = await db.collection('building').count()
const total = countResult.total
const batchTimes = Math.ceil(total / 100)
const tasks = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('building').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
tasks.push(promise)
}
return (await Promise.all(tasks)).reduce((acc, cur) => {
return {
data: acc.data.concat(cur.data),
errMsg: acc.errMsg,
}
})
}
小程序端调用云函数,rerult是null,说明云函数有错误,可以在云开发中看一下云函数调用日志,看看是不是执行时发生错误。如果是,说明云函数代码中有错误
还有,async和await要成对出现的