在云函数查询里面,加入orderBy关键字查询之后速度变慢,是正常的吗?
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('desk').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('desk').skip(i * MAX_LIMIT).limit(MAX_LIMIT).orderBy("room","asc").orderBy("numb","asc").get() // const promise = db.collection('desk').skip(i * MAX_LIMIT).limit(MAX_LIMIT).orderBy("id","asc").get() tasks.push(promise) } // 等待所有 return (await Promise.all(tasks)).reduce((acc, cur) => { return { data: acc.data.concat(cur.data), errMsg: acc.errMsg, } }) } 加入orderBy之后就要4s左右查询时间,删掉orderBy就是1s都不用