const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const MAX_LIMIT = 100
exports.main = async (event, context) => {
const countResult = await db.collection('user').count()
const total = countResult.total
const batchTimes = Math.ceil(total / 100)
const tasks = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('user').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,
}
})
}
在index.js中能查询到数据,在另外一个search.js中查询不到。
已经处理,打印有问题。