SDK数据库 Command查询数组操作符


本文整理自网络,侵删。

Command.all(values: any[]): Command

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

数组查询操作符。用于数组字段的查询筛选条件,要求数组字段中包含给定数组的所有元素。

参数

values: any[]

返回值

Command

示例代码 1:普通数组

找出 tags 数组字段同时包含 cloud 和 database 的记录

const _ = db.command
db.collection('todos').where({
  tags: _.all(['cloud', 'database'])
})
.get({
  success: console.log,
  fail: console.error
})

示例代码 2:对象数组

如果数组元素是对象,则可以用 _.elemMatch 匹配对象的部分字段

假设有字段 places 定义如下:

{
  "type": string
  "area": number
  "age": number
}

找出数组字段中至少同时包含一个满足 “area 大于 100 且 age 小于 2” 的元素和一个满足 “type 为 mall 且 age 大于 5” 的元素

const _ = db.command
db.collection('todos').where({
  places: _.all([
    _.elemMatch({
      area: _.gt(100),
      age: _.lt(2),
    }),
    _.elemMatch({
      name: 'mall',
      age: _.gt(5),
    }),
  ]),
})
.get({
  success: console.log,
  fail: console.error,
})


阅读剩余部分

相关阅读 >>

微信小程序api 绘图设置填充样式setfillstyle

微信小程序api 文件-获取已保存的本地缓存文件列表

微信小程序 运维中心getscenelist

微信小程序 快递接口(商家查看)-接口规则

微信小程序 分享到朋友圈(beta)

微信小程序开放数据 ad-custom

微信小程序 ocridcard

微信小程序使用moveto把路径移动到画布中的指定点,不创建线条

微信小程序api 实时语音-监听视频状态变化事件

微信小程序工具 稳定版 stable build 更新日志

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




打赏

取消

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

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

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

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

评论

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