青春纸盒子

文: 芦苇

你喜欢我笑的样子

我靠上了落寞的窗子

晚风吹起了我的袖子

明月沾湿了你的眸子


转身,你走出了两个人的圈子

树影婆娑,整座院子


挽起袖子

回头,把揽你忧伤一地的影子

装进,青春,这纸盒子


更多代码请关注我的微信小程序: "ecoder"

luwei0915

导航

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
//  }]
// }

posted on 2020-07-27 15:46  芦苇の  阅读(114)  评论(0)    收藏  举报