zoukankan      html  css  js  c++  java
  • demo_10_02 云数据库聚合_bucket_02 bucketAuto

    // 1. 数据库数据
    // {
    //  "items": { // 集合(表名)
    //      "data": [ // 数据
    //          {
    //            "_id": 1,
    //            "price": 10.5
    //          },
    //          {
    //            "_id": 2,
    //            "price": 50.3
    //          },
    //          {
    //            "_id": 3,
    //            "price": 20.8
    //          },
    //          {
    //            "_id": 4,
    //            "price": 80.2
    //          },
    //          {
    //            "_id": 5,
    //            "price": 200.3
    //          }
    //      ]
    //  }
    // }

    // 02. 聚合操作
    'use strict';
    const db = uniCloud.database();
    const $ = db.command.aggregate;
    exports.main = async(event, context) => {
        let res = await db.collection('items').aggregate()
            .bucketAuto({
                // 以price分组
                groupBy: '$price',
                // 分3组
                buckets: 3
            })
            .end()
        return res;
    };

    // 聚合之后的返回值
    // {
    //  "affectedDocs": 3,
    //  "data": [{
    //      "_id": {
    //          "max": 50.3,
    //          "min": 10.5
    //      },
    //      "count": 2
    //  }, {
    //      "_id": {
    //          "max": 200.3,
    //          "min": 50.3
    //      },
    //      "count": 2
    //  }, {
    //      "_id": {
    //          "max": 200.3,
    //          "min": 200.3
    //      },
    //      "count": 1
    //  }]
    // }
  • 相关阅读:
    maven的pom.xml文件详细说明
    python 给视频添加马赛克
    cv2.VideoCapture 图像旋转问题
    三分钟理解知识蒸馏
    深度学习、机器学习常见概念及理解(持续更新)
    python用直方图规定化实现图像风格转换
    1分钟理解人体姿态估计与行为识别
    数据清洗要点
    3分钟理解NMS非极大值抑制
    python用pandas遍历csv文件
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13385798.html
Copyright © 2011-2022 走看看