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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Aggregate·記錄分組

Aggregate.group(object: Object): Aggregate

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

為秦淮等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及秦淮網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站建設、成都網(wǎng)站設計、秦淮網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

聚合階段。將輸入記錄按給定表達式分組,輸出時每個記錄代表一個分組,每個記錄的 _id 是區(qū)分不同組的 key。輸出記錄中也可以包括累計值,將輸出字段設為累計值即會從該分組中計算累計值。

參數(shù)

object: Object

返回值

Aggregate

API 說明

group 的形式如下:

group({
  _id: ,
  : ,
  ...
  : 
})

_id 參數(shù)是必填的,如果填常量則只有一組。其他字段是可選的,都是累計值,用 $.sum 等累計器,但也可以使用其他表達式。

累計器必須是以下操作符之一:

  • addToSet
  • avg
  • first
  • last
  • max
  • min
  • push
  • stdDevPop
  • stdDevSamp
  • sum

內存限制

該階段有 100M 內存使用限制。

示例 1:按字段值分組

假設集合 avatar 有如下記錄:

{
  _id: "1",
  alias: "john",
  region: "asia",
  scores: [40, 20, 80],
  coins: 100
}
{
  _id: "2",
  alias: "arthur",
  region: "europe",
  scores: [60, 90],
  coins: 20
}
{
  _id: "3",
  alias: "george",
  region: "europe",
  scores: [50, 70, 90],
  coins: 50
}
{
  _id: "4",
  alias: "john",
  region: "asia",
  scores: [30, 60, 100, 90],
  coins: 40
}
{
  _id: "5",
  alias: "george",
  region: "europe",
  scores: [20],
  coins: 60
}
{
  _id: "6",
  alias: "john",
  region: "asia",
  scores: [40, 80, 70],
  coins: 120
}
const $ = db.command.aggregate
db.collection('avatar').aggregate()
  .group({
    _id: '$alias',
    num: $.sum(1)
  })
  .end()

返回結果如下:

{
  "_id": "john",
  "num": 3
}
{
  "_id": "authur",
  "num": 1
}
{
  "_id": "george",
  "num": 2
}

示例 2:按多個值分組

可以給 _id 傳入記錄的方式按多個值分組。還是沿用上面的示例數(shù)據(jù),按各個區(qū)域(region)獲得相同最高分(score)的來分組,并求出各組虛擬幣(coins)的總量:

const $ = db.command.aggregate
db.collection('avatar').aggregate()
  .group({
    _id: {
      region: '$region',
      maxScore: $.max('$scores')
    },
    totalCoins: $.sum('$coins')
  })
  .end()

返回結果如下:

{
  "_id": {
    "region": "asia",
    "maxScore": 80
  },
  "totalCoins": 220
}
{
  "_id": {
    "region": "asia",
    "maxScore": 100
  },
  "totalCoins": 100
}
{
  "_id": {
    "region": "europe",
    "maxScore": 90
  },
  "totalCoins": 70
}
{
  "_id": {
    "region": "europe",
    "maxScore": 20
  },
  "totalCoins": 60
}

文章名稱:創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Aggregate·記錄分組
本文鏈接:http://m.5511xx.com/article/djshdgc.html