SDK数据库 Collection构建查询条件


本文整理自网络,侵删。

Collection.where(condition: Object): Collection

支持端:小程序 , 云函数 , Web

指定查询条件,返回带新查询条件的新的集合引用

参数

condition: Object

查询条件

返回值

Collection

示例代码

const _ = db.command
const result = await db.collection('todos').where({
  price: _.lt(100)
}).get()


Collection.limit(value: number): Collection

支持端:小程序 , 云函数 , Web

指定查询结果集数量上限

参数

value: number

返回值

Collection

说明

limit 在小程序端默认及最大上限为 20,在云函数端默认及最大上限为 1000

示例代码

db.collection('todos').limit(10)
  .get()
  .then(console.log)
  .catch(console.error)

Collection.orderBy(fieldPath: string, string: order): Collection

支持端:小程序 , 云函数 , Web

指定查询排序条件

参数

fieldPath: string

string: order

返回值

Collection

说明

方法接受一个必填字符串参数 fieldName 用于定义需要排序的字段,一个字符串参数 order 定义排序顺序。order 只能取 asc 或 desc。

如果需要对嵌套字段排序,需要用 "点表示法" 连接嵌套字段,比如 style.color 表示字段 style 里的嵌套字段 color。

阅读剩余部分

相关阅读 >>

微信小程序 欠费支付

微信小程序 收藏

微信小程序 城市服务接入安全检测

微信小程序api-设备-手机联系人

微信小程序 组件生命周期

微信小程序云开发 代金券

微信小程序 版本分布

微信小程序 运行环境

微信小程序api 在设置界面中修改对该小程序的授权信息

微信小程序工具 体验评分

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




打赏

取消

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

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

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

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

评论

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