SDK数据库 Command聚合操作符布尔操作符


本文整理自网络,侵删。

AggregateCommand.and(value: Expression[]): Object

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

聚合操作符。给定多个表达式,and 仅在所有表达式都返回 true 时返回 true,否则返回 false。

参数

value: Expression[]

[<expression1>, <expression2>, ...]

返回值

Object

API 说明

语法如下:

db.command.aggregate.and([<expression1>, <expression2>, ...])

如果表达式返回 false、null、0、或 undefined,表达式会解析为 false,否则对其他返回值都认为是 true。

示例代码

假设集合 price 有如下记录:

{ "_id": 1, "min": 10, "max": 100 }
{ "_id": 2, "min": 60, "max": 80 }
{ "_id": 3, "min": 30, "max": 50 }

求 min 大于等于 30 且 max 小于等于 80 的记录。

const $ = db.command.aggregate
db.collection('price').aggregate()
  .project({
    fullfilled: $.and([$.gte(['$min', 30]), $.lte(['$max', 80])])
  })
  .end()

返回结果如下:

{ "_id": 1, "fullfilled": false }
{ "_id": 2, "fullfilled": true }
{ "_id": 3, "fullfilled": true }

AggregateCommand.not(value: Expression): Object

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

聚合操作符。给定一个表达式,如果表达式返回 true,则 not 返回 false,否则返回 true。注意表达式不能为逻辑表达式(and、or、nor、not)。

参数

value: Expression

表达式

返回值

Object

API 说明

语法如下:

db.command.aggregate.not(<expression>)

如果表达式返回 false、null、0、或 undefined,表达式会解析为 false,否则对其他返回值都认为是 true。

示例代码

假设集合 price 有如下记录:

{ "_id": 1, "min": 10, "max": 100 }
{ "_id": 2, "min": 60, "max": 80 }
{ "_id": 3, "min": 30, "max": 50 }

求 min 不大于 40 的记录。

const $ = db.command.aggregate
db.collection('price').aggregate()
  .project({
    fullfilled: $.not($.gt(['$min', 40]))
  })
  .end()

返回结果如下:

{ "_id": 1, "fullfilled": true }
{ "_id": 2, "fullfilled": false }
{ "_id": 3, "fullfilled": true }

AggregateCommand.or(value: Expression[]): Object

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

聚合操作符。给定多个表达式,如果任意一个表达式返回 true,则 or 返回 true,否则返回 false。

参数

value: Expression[]

[<expression1>, <expression2>, ...]

返回值

Objectu

API 说明

语法如下:

db.command.aggregate.or([<expression1>, <expression2>, ...])

如果表达式返回 false、null、0、或 undefined,表达式会解析为 false,否则对其他返回值都认为是 true。

示例代码

假设集合 price 有如下记录:

{ "_id": 1, "min": 10, "max": 100 }
{ "_id": 2, "min": 60, "max": 80 }
{ "_id": 3, "min": 30, "max": 50 }

求 min 小于 40 且 max 大于 60 的记录。

const $ = db.command.aggregate
db.collection('price').aggregate()
  .project({
    fullfilled: $.or([$.lt(['$min', 30]), $.gt(['$max', 60])])
  })
  .end()

返回结果如下:

{ "_id": 1, "fullfilled": true }
{ "_id": 2, "fullfilled": false }
{ "_id": 3, "fullfilled": true }



标签:微信小程序

相关阅读 >>

微信小程序 get

微信小程序 查询欠费用户列表

微信小程序云开发 api数据库迁移状态查询

微信小程序 weui半屏弹窗

微信小程序 小程序搜索imagesearch

微信小程序 运行环境

微信小程序api 文件-描述文件状态的对象

微信小程序api 保留当前页面

微信小程序api 绘图setlinecap(设置线条端点样式)

微信小程序云开发服务端数据库api 获取数据库查询及更新指令

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




打赏

取消

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

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

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

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

评论

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