同时也支持按多个字段排序,多次调用 orderBy 即可,多字段排序时的顺序会按照 orderBy 调用顺序先后对多个字段排序
示例代码:按一个字段排序
按进度排升序取待办事项
db.collection('todos').orderBy('progress', 'asc')
.get()
.then(console.log)
.catch(console.error)
示例代码:按多个字段排序
先按 progress 排降序(progress 越大越靠前)、再按 description 排升序(字母序越前越靠前)取待办事项:
db.collection('todos')
.orderBy('progress', 'desc')
.orderBy('description', 'asc')
.get()
.then(console.log)
.catch(console.error)
Collection.skip(offset: number): Collection
支持端:小程序 , 云函数 , Web指定查询返回结果时从指定序列后的结果开始返回,常用于分页
参数
offset: number
返回值
Collection
示例代码
db.collection('todos').skip(10)
.get()
.then(console.log)
.catch(console.error)
Collection.field(projection: Object): Collection
支持端:小程序 , 云函数 , Web指定返回结果中记录需返回的字段
参数
projection: Object
返回值
Collection
说明
方法接受一个必填对象用于指定需返回的字段,对象的各个 key 表示要返回或不要返回的字段,value 传入 true|false(或 1|-1)表示要返回还是不要返回。
示例代码
只返回 description, done 和 progress 三个字段:
db.collection('todos').field({
description: true,
done: true,
progress: true,
})
.get()
.then(console.log)
.catch(console.error)
标签:微信小程序
相关阅读 >>
微信小程序api 绘图globalcompositeoperation
更多相关阅读请进入《微信小程序》频道 >>
Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者