SDK数据库 Collection构建查询条件


当前第2页 返回上一页

同时也支持按多个字段排序,多次调用 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 位置

微信小程序 广告-视频广告

微信小程序api 绘图fillrect(填充矩形)

微信小程序 uploadtempmedia

微信小程序云开发api 更新指令

微信小程序云开发 云开发能力

微信小程序api 绘图globalcompositeoperation

sdk数据库 aggregate传递字段

微信小程序云开发服务端数据库api 获取集合的引用

微信小程序 扩展组件绘制canvas

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...