zoukankan      html  css  js  c++  java
  • demo_10_05 云数据库聚合_limit

    // 1. 数据库数据
    // {
    //  "items": { // 集合(表名)
    //      "data": [ // 数据
    //          {
    //              "_id": "1",
    //              "price": 10
    //          },
    //          {
    //              "_id": "2",
    //              "price": 50
    //          },
    //          {
    //              "_id": "3",
    //              "price": 20
    //          },
    //          {
    //              "_id": "4",
    //              "price": 80
    //          },
    //          {
    //              "_id": "5",
    //              "price": 200
    //          }
    //      ]
    //  }
    // }

    // 02. 聚合操作 limit
    // 聚合阶段,限制输出到下一阶段的记录数。
    'use strict';
    const db = uniCloud.database();
    const $ = db.command.aggregate;
    exports.main = async(event, context) => {
        let res = await db.collection('items').aggregate()
            // 返回价格大于 20 的记录的最小的两个记录:
            .match({
                price: $.gt(20)
            })
            .sort({
                price: 1,
            })
            .limit(2)
            .end();
        return res;
    };

    // 聚合之后的返回值
    // {
    //  "affectedDocs": 2,
    //  "data": [{
    //      "_id": "2",
    //      "price": 50
    //  }, {
    //      "_id": "4",
    //      "price": 80
    //  }]
    // }
  • 相关阅读:
    TCP粘包的拆包处理
    字节序列化
    同步,异步,阻塞和非阻塞
    用Doxygen生成文档
    Visual Studio新建的源文件的默认编码
    Boost编程之获取可执行文件的当前路径
    特征点寻找的基础数据结构和函数
    寻找Harris、Shi-Tomasi和亚像素角点
    特征点的基本概念和如何找到它们
    工业相机与普通相机的差别
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13387012.html
Copyright © 2011-2022 走看看