日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Command·聚合操作符·集合操作符

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|成都網(wǎng)站維護|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計與制作經(jīng)驗,為許多企業(yè)提供了網(wǎng)站定制設(shè)計服務(wù),案例作品覆蓋成都護欄打樁機等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身建設(shè)品質(zhì)網(wǎng)站。

聚合操作符。輸入一個數(shù)組,或者數(shù)組字段的表達式。如果數(shù)組中所有元素均為真值,那么返回 true,否則返回 false??諗?shù)組永遠返回 true。

參數(shù)

value: Expression[]

[]

返回值

Object

API 說明

語法如下:

allElementsTrue([])

示例代碼

假設(shè)集合 test 有如下記錄:

{ "_id": 1, "array": [ true ] }
{ "_id": 2, "array": [ ] }
{ "_id": 3, "array": [ false ] }
{ "_id": 4, "array": [ true, false ] }
{ "_id": 5, "array": [ 0 ] }
{ "_id": 6, "array": [ "stark" ] }

下面的代碼使用 allElementsTrue(),判斷 array 字段中是否均為真值:

const $ = db.command.aggregate
db.collection('price')
  .aggregate()
  .project({
    isAllTrue: $.allElementsTrue(['$array'])
  })
  .end()

返回結(jié)果如下:

{ "_id": 1, "isAllTrue": true }
{ "_id": 2, "isAllTrue": true }
{ "_id": 3, "isAllTrue": false }
{ "_id": 4, "isAllTrue": false }
{ "_id": 5, "isAllTrue": false }
{ "_id": 6, "isAllTrue": true }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符。輸入一個數(shù)組,或者數(shù)組字段的表達式。如果數(shù)組中任意一個元素為真值,那么返回 true,否則返回 false。空數(shù)組永遠返回 false。

參數(shù)

value: Expression[]

[]

返回值

Object

API 說明

語法如下:

anyElementTrue([])

示例代碼

假設(shè)集合 test 有如下記錄:

{ "_id": 1, "array": [ true ] }
{ "_id": 2, "array": [ ] }
{ "_id": 3, "array": [ false ] }
{ "_id": 4, "array": [ true, false ] }
{ "_id": 5, "array": [ 0 ] }
{ "_id": 6, "array": [ "stark" ] }

下面的代碼使用 anyElementTrue(),判斷 array 字段中是否含有真值:

const $ = db.command.aggregate
db.collection('price')
  .aggregate()
  .project({
    isAnyTrue: $.anyElementTrue(['$array'])
  })
  .end()

返回結(jié)果如下:

{ "_id": 1, "isAnyTrue": true }
{ "_id": 2, "isAnyTrue": false }
{ "_id": 3, "isAnyTrue": false }
{ "_id": 4, "isAnyTrue": true }
{ "_id": 5, "isAnyTrue": false }
{ "_id": 6, "isAnyTrue": true }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符,輸入兩個集合,輸出只存在于第一個集合中的元素。

參數(shù)

value: Expression[]

[, ]

返回值

Object

API 說明

使用形式如下:

setDifference([, ])

示例代碼

假設(shè)集合 test 存在以下數(shù)據(jù):

{ "_id": 1, "A": [ 1, 2 ], "B": [ 1, 2 ] }
{ "_id": 2, "A": [ 1, 2 ], "B": [ 2, 1, 2 ] }
{ "_id": 3, "A": [ 1, 2 ], "B": [ 1, 2, 3 ] }
{ "_id": 4, "A": [ 1, 2 ], "B": [ 3, 1 ] }
{ "_id": 5, "A": [ 1, 2 ], "B": [ ] }
{ "_id": 6, "A": [ 1, 2 ], "B": [ {}, [] ] }
{ "_id": 7, "A": [ ], "B": [ ] }
{ "_id": 8, "A": [ ], "B": [ 1 ] }

下面的代碼使用 setDifference,找到只存在于 B 中的數(shù)字:

db.collection('test')
  .aggregate()
  .project({
    isBOnly: $.setDifference(['$B', '$A'])
  })
  .end()
{ "_id": 1, "isBOnly": [] }
{ "_id": 2, "isBOnly": [3] }
{ "_id": 3, "isBOnly": [3] }
{ "_id": 4, "isBOnly": [5] }
{ "_id": 5, "isBOnly": [] }
{ "_id": 6, "isBOnly": [{}, []] }
{ "_id": 7, "isBOnly": [] }
{ "_id": 8, "isBOnly": [1] }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符,輸入兩個集合,判斷兩個集合中包含的元素是否相同(不考慮順序、去重)。

參數(shù)

value: Expression[]

[, ]

返回值

Object

API 說明

使用形式如下:

setEquals([, ])

示例代碼

假設(shè)集合 test 存在以下數(shù)據(jù):

{ "_id": 1, "A": [ 1, 2 ], "B": [ 1, 2 ] }
{ "_id": 2, "A": [ 1, 2 ], "B": [ 2, 1, 2 ] }
{ "_id": 3, "A": [ 1, 2 ], "B": [ 1, 2, 3 ] }
{ "_id": 4, "A": [ 1, 2 ], "B": [ 3, 1 ] }
{ "_id": 5, "A": [ 1, 2 ], "B": [ ] }
{ "_id": 6, "A": [ 1, 2 ], "B": [ {}, [] ] }
{ "_id": 7, "A": [ ], "B": [ ] }
{ "_id": 8, "A": [ ], "B": [ 1 ] }

下面的代碼使用 setEquals,判斷兩個集合中包含的元素是否相同:

db.collection('test')
  .aggregate()
  .project({
    sameElements: $.setEquals(['$A', '$B'])
  })
  .end()
{ "_id": 1, "sameElements": true }
{ "_id": 2, "sameElements": true }
{ "_id": 3, "sameElements": false }
{ "_id": 4, "sameElements": false }
{ "_id": 5, "sameElements": false }
{ "_id": 6, "sameElements": false }
{ "_id": 7, "sameElements": true }
{ "_id": 8, "sameElements": false }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符,輸入兩個集合,輸出兩個集合的交集。

參數(shù)

value: Expression[]

[, ]

返回值

Object

API 說明

使用形式如下:

setIntersection([, ])

示例代碼

假設(shè)集合 test 存在以下數(shù)據(jù):

{ "_id": 1, "A": [ 1, 2 ], "B": [ 1, 2 ] }
{ "_id": 2, "A": [ 1, 2 ], "B": [ 2, 1, 2 ] }
{ "_id": 3, "A": [ 1, 2 ], "B": [ 1, 2, 3 ] }
{ "_id": 4, "A": [ 1, 2 ], "B": [ 3, 1 ] }
{ "_id": 5, "A": [ 1, 2 ], "B": [ ] }
{ "_id": 6, "A": [ 1, 2 ], "B": [ {}, [] ] }
{ "_id": 7, "A": [ ], "B": [ ] }
{ "_id": 8, "A": [ ], "B": [ 1 ] }

下面的代碼使用 setIntersection,輸出兩個集合的交集:

db.collection('test')
  .aggregate()
  .project({
    commonToBoth: $.setIntersection(['$A', '$B'])
  })
  .end()

輸出如下:

{ "_id": 1, "commonToBoth": [ 1, 2 ] }
{ "_id": 2, "commonToBoth": [ 1, 2 ] }
{ "_id": 3, "commonToBoth": [ 1, 2 ] }
{ "_id": 4, "commonToBoth": [ 1 ] }
{ "_id": 5, "commonToBoth": [ ] }
{ "_id": 6, "commonToBoth": [ ] }
{ "_id": 7, "commonToBoth": [ ] }
{ "_id": 8, "commonToBoth": [ ] }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符,輸入兩個集合,判斷第一個集合是否是第二個集合的子集。

參數(shù)

value: Expression[]

[, ]

返回值

Object

API 說明

使用形式如下:

setIsSubset([, ])

示例代碼

假設(shè)集合 test 存在以下數(shù)據(jù):

{ "_id": 1, "A": [ 1, 2 ], "B": [ 1, 2 ] }
{ "_id": 2, "A": [ 1, 2 ], "B": [ 2, 1, 2 ] }
{ "_id": 3, "A": [ 1, 2 ], "B": [ 1, 2, 3 ] }
{ "_id": 4, "A": [ 1, 2 ], "B": [ 3, 1 ] }
{ "_id": 5, "A": [ 1, 2 ], "B": [ ] }
{ "_id": 6, "A": [ 1, 2 ], "B": [ {}, [] ] }
{ "_id": 7, "A": [ ], "B": [ ] }
{ "_id": 8, "A": [ ], "B": [ 1 ] }

下面的代碼使用 setIsSubset,判斷第一個集合是否是第二個集合的子集:

db.collection('test')
  .aggregate()
  .project({
    AisSubsetOfB: $.setIsSubset(['$A', '$B'])
  })
  .end()
{ "_id": 1, "AisSubsetOfB": true }
{ "_id": 2, "AisSubsetOfB": true }
{ "_id": 3, "AisSubsetOfB": true }
{ "_id": 4, "AisSubsetOfB": false }
{ "_id": 5, "AisSubsetOfB": false }
{ "_id": 6, "AisSubsetOfB": false }
{ "_id": 7, "AisSubsetOfB": true }
{ "_id": 8, "AisSubsetOfB": true }

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

支持端:小程序 2.7.4, 云函數(shù) 0.8.1, Web

聚合操作符,輸入兩個集合,輸出兩個集合的并集。

參數(shù)

value: Expression[]

[, ]

返回值

Object

API 說明

使用形式如下:

setUnion([, ])

示例代碼

假設(shè)集合 test 存在以下數(shù)據(jù):

{ "_id": 1, "A": [ 1, 2 ], "B": [ 1, 2 ] }
{ "_id": 2, "A": [ 1, 2 ], "B": [ 2, 1, 2 ] }
{ "_id": 3, "A": [ 1, 2 ], "B": [ 1, 2, 3 ] }
{ "_id": 4, "A": [ 1, 2 ], "B": [ 3, 1 ] }
{ "_id": 5, "A": [ 1, 2 ], "B": [ ] }
{ "_id": 6, "A": [ 1, 2 ], "B": [ {}, [] ] }
{ "_id": 7, "A": [ ], "B": [ ] }
{ "_id": 8, "A": [ ], "B": [ 1 ] }

下面的代碼使用 setUnion,輸出兩個集合的并集:

db.collection('test')
  .aggregate()
  .project({
    AB: $.setUnion(['$A', '$B'])
  })
  .end()

輸出如下:

{ "_id": 1, "AB": [ 1, 2 ] }
{ "_id": 2, "AB": [ 1, 2 ] }
{ "_id": 3, "AB": [ 1, 2, 3 ] }
{ "_id": 4, "AB": [ 1, 2, 3 ] }
{ "_id": 5, "AB": [ 1, 2 ] }
{ "_id": 6, "AB": [ 1, 2, {}, [] ] }
{ "_id": 7, "AB": [ ] }
{ "_id": 8, "AB": [ 1 ] }


當(dāng)前名稱:創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Command·聚合操作符·集合操作符
URL標(biāo)題:http://m.5511xx.com/article/dhhsdpc.html