uni-app getCount:true失效
uni-app getCount:true失效
示例代码:
let res1 = await collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip) // 跳过前20条
.limit(limit) // 获取20条
.orderBy(orderField, orderType)
.get({
getCount: true
})
操作步骤:
let res1 = await collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip) // 跳过前20条
.limit(limit) // 获取20条
.orderBy(orderField, orderType)
.get({
getCount: true
})
预期结果:
let res1 = await collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip) // 跳过前20条
.limit(limit) // 获取20条
.orderBy(orderField, orderType)
.get({
getCount: true
})
实际结果:
let res1 = await collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip) // 跳过前20条
.limit(limit) // 获取20条
.orderBy(orderField, orderType)
.get({
getCount: true
})
bug描述:
使用await时,getCount: true失效,没有返回count,使用getOne也失效
更多关于uni-app getCount:true失效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
getOne,getCount都是jql里面添加的功能,云函数里面目前不能用。即将推出云函数使用jql语法的扩展库。还有你确实需要先skip+limit再orderBy吗?
更多关于uni-app getCount:true失效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
回复 Syone: 云函数已经能用jql扩展了 https://uniapp.dcloud.net.cn/uniCloud/jql-cloud.html
getCount: true 在 uni-app 云函数中失效,通常是由于以下原因导致的:
-
云函数版本问题:请确认使用的是 uniCloud 2.0 及以上版本。旧版本中
getCount参数可能存在兼容性问题。 -
查询链顺序:确保
getCount参数在查询链的最后一步设置。你的代码顺序是正确的。 -
await 使用问题:你提到使用 await 时失效,可以尝试以下两种方式:
// 方式一:使用 then 回调
collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip)
.limit(limit)
.orderBy(orderField, orderType)
.get({
getCount: true
}).then(res => {
console.log(res)
})
// 方式二:检查异步上下文
async function getData() {
try {
let res1 = await collection.where({
filename: new RegExp(`.*${keywords}.*`, 'i')
})
.skip(skip)
.limit(limit)
.orderBy(orderField, orderType)
.get({
getCount: true
})
console.log('返回结果:', res1)
} catch(err) {
console.error('查询错误:', err)
}
}
- 检查返回结果结构:成功时返回的数据结构应为:
{
data: [], // 查询到的数据数组
count: 0, // 符合条件的总记录数
affectedDocs: 0 // 实际查询到的文档数
}


