新聞中心
AggregateCommand.and(value: Expression[]): Object
支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web
網(wǎng)站設計制作過程拒絕使用模板建站;使用PHP+MYSQL原生開發(fā)可交付網(wǎng)站源代碼;符合網(wǎng)站優(yōu)化排名的后臺管理系統(tǒng);網(wǎng)站設計制作、成都網(wǎng)站設計收費合理;免費進行網(wǎng)站備案等企業(yè)網(wǎng)站建設一條龍服務.我們是一家持續(xù)穩(wěn)定運營了十年的創(chuàng)新互聯(lián)網(wǎng)站建設公司。
聚合操作符。給定多個表達式,and 僅在所有表達式都返回 true 時返回 true,否則返回 false。
參數(shù)
value: Expression[]
[
返回值
Object
API 說明
語法如下:
db.command.aggregate.and([, , ...])
如果表達式返回 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, 云函數(shù) 0.8.1, Web
聚合操作符。給定一個表達式,如果表達式返回 true,則 not 返回 false,否則返回 true。注意表達式不能為邏輯表達式(and、or、nor、not)。
參數(shù)
value: Expression
表達式
返回值
Object
API 說明
語法如下:
db.command.aggregate.not()
如果表達式返回 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, 云函數(shù) 0.8.1, Web
聚合操作符。給定多個表達式,如果任意一個表達式返回 true,則 or 返回 true,否則返回 false。
參數(shù)
value: Expression[]
[
返回值
Objectu
API 說明
語法如下:
db.command.aggregate.or([, , ...])
如果表達式返回 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 }
當前題目:創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Command·聚合操作符·布爾操作符
標題網(wǎng)址:http://www.dlmjj.cn/article/dhppdsc.html


咨詢
建站咨詢

