pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='XMKN1'></bdo><ul id='XMKN1'></ul>

<tfoot id='XMKN1'></tfoot>
  • <legend id='XMKN1'><style id='XMKN1'><dir id='XMKN1'><q id='XMKN1'></q></dir></style></legend>

      <small id='XMKN1'></small><noframes id='XMKN1'>

      1. <i id='XMKN1'><tr id='XMKN1'><dt id='XMKN1'><q id='XMKN1'><span id='XMKN1'><b id='XMKN1'><form id='XMKN1'><ins id='XMKN1'></ins><ul id='XMKN1'></ul><sub id='XMKN1'></sub></form><legend id='XMKN1'></legend><bdo id='XMKN1'><pre id='XMKN1'><center id='XMKN1'></center></pre></bdo></b><th id='XMKN1'></th></span></q></dt></tr></i><div class="rbtf9xz" id='XMKN1'><tfoot id='XMKN1'></tfoot><dl id='XMKN1'><fieldset id='XMKN1'></fieldset></dl></div>
      2. 如何在 PouchDB 上模擬聚合函數(shù) avg、sum、max、min

        How to simulating the aggregate functions avg, sum, max, min, and count on PouchDB?(如何在 PouchDB 上模擬聚合函數(shù) avg、sum、max、min 和 count?)
                <tbody id='g8VPG'></tbody>
                <bdo id='g8VPG'></bdo><ul id='g8VPG'></ul>

                <tfoot id='g8VPG'></tfoot>
                  <legend id='g8VPG'><style id='g8VPG'><dir id='g8VPG'><q id='g8VPG'></q></dir></style></legend>
                  <i id='g8VPG'><tr id='g8VPG'><dt id='g8VPG'><q id='g8VPG'><span id='g8VPG'><b id='g8VPG'><form id='g8VPG'><ins id='g8VPG'></ins><ul id='g8VPG'></ul><sub id='g8VPG'></sub></form><legend id='g8VPG'></legend><bdo id='g8VPG'><pre id='g8VPG'><center id='g8VPG'></center></pre></bdo></b><th id='g8VPG'></th></span></q></dt></tr></i><div class="08ks2u2" id='g8VPG'><tfoot id='g8VPG'></tfoot><dl id='g8VPG'><fieldset id='g8VPG'></fieldset></dl></div>

                • <small id='g8VPG'></small><noframes id='g8VPG'>

                  本文介紹了如何在 PouchDB 上模擬聚合函數(shù) avg、sum、max、min 和 count?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  有誰知道如何在 PouchDB 數(shù)據(jù)庫上創(chuàng)建聚合函數(shù),例如 avg、sum、max 和 min.我創(chuàng)建了一個簡單的應(yīng)用程序來測試 PouchDB.我仍然不知道如何運行這些命令.提前致謝.

                  Does anyone know how to create aggregate functions, for example avg, sum, max and min on PouchDB database. I created a simple application to test the PouchDB. I'm still not figured out how to run these commands. Thanks in advance.

                  例如.您如何獲得數(shù)字"字段的最高、最低或平均值?

                  For example. How do you get the highest, lowest or average for the "number" field?

                  我的主要 Ionic 2 組件

                  My main Ionic 2 component

                  import {Component} from '@angular/core';
                  import {Platform, ionicBootstrap} from 'ionic-angular';
                  import {StatusBar} from 'ionic-native';
                  import {HomePage} from './pages/home/home';
                  declare var require: any;
                  var pouch = require('pouchdb');
                  var pouchFind = require('pouchdb-find');
                  @Component({
                      template: '<ion-nav [root]="rootPage"></ion-nav>'
                  })
                  export class MyApp {
                      rootPage: any = HomePage;
                      db: any;
                      value: any;
                      constructor(platform: Platform) {
                          platform.ready().then(() => {
                              StatusBar.styleDefault();
                          });
                          pouch.plugin(pouchFind);
                          this.db = new pouch('friendsdb');
                          let docs = [
                              {
                                  '_id': '1',
                                  'number': 10,
                                  'values': '1, 2, 3',
                                  'loto': 'fooloto'
                              },
                              {
                                  '_id': '2',
                                  'number': 12,
                                  'values': '4, 7, 9',
                                  'loto': 'barloto'
                              },
                              {
                                  '_id': '3',
                                  'number': 13,
                                  'values': '9, 4, 5',
                                  'loto': 'fooloto'
                              }
                          ];
                          this.db.bulkDocs(docs).then(function (result) {
                              console.log(result);
                          }).catch(function (err) {
                              console.log(err);
                          });
                      }
                  }
                  ionicBootstrap(MyApp);
                  

                  推薦答案

                  您可以使用 map/reduce 函數(shù) 來自 PouchDB 的 db.query() 方法 以獲得平均值、總和、最大或任何其他類型的聚合文檔.

                  You can use the map/reduce functions of the db.query() method from PouchDB to get the average, sum, largest or any other kind of aggregation of the docs.

                  我創(chuàng)建了一個 演示 JSBin fiddle 和一個正在運行的示例.我將函數(shù)的解釋直接添加到代碼中(如下)作為注釋,因為我認(rèn)為它會更簡單.

                  I have created a demo JSBin fiddle with a running example. I added the explanation of the functions directly into the code (below) as comments, as I thought it'd be simpler.

                  var db = new PouchDB('friendsdb');
                  var docs = [
                        {'_id': '1', 'number': 10, 'values': '1, 2, 3', 'loto': 'fooloto'},
                        {'_id': '2', 'number': 12, 'values': '4, 7, 9', 'loto': 'barloto'},
                        {'_id': '3', 'number': 13, 'values': '9, 4, 5', 'loto': 'fooloto'}
                  ];
                  
                  db.bulkDocs(docs).then(function(result) {
                    querySum();
                    queryLargest();
                    querySmallest();
                    queryAverage();
                  }).catch(function(err) {
                    console.log(err);
                  });
                  
                  function querySum() {
                    function map(doc) {
                      // the function emit(key, value) takes two arguments
                      // the key (first) arguments will be sent as an array to the reduce() function as KEYS
                      // the value (second) arguments will be sent as an array to the reduce() function as VALUES
                      emit(doc._id, doc.number);
                    }
                    function reduce(keys, values, rereduce) {
                      // keys:
                      //   here the keys arg will be an array containing everything that was emitted as key in the map function...
                      //   ...plus the ID of each doc (that is included automatically by PouchDB/CouchDB).
                      //   So each element of the keys array will be an array of [keySentToTheEmitFunction, _idOfTheDoc]
                      //
                      // values
                      //   will be an array of the values emitted as value
                      console.info('keys ', JSON.stringify(keys));
                      console.info('values ', JSON.stringify(values));
                      // check for more info: http://couchdb.readthedocs.io/en/latest/couchapp/views/intro.html
                  
                  
                      // So, since we want the sum, we can just sum all items of the values array
                      // (there are several ways to sum an array, I'm just using vanilla for to keep it simple)
                      var i = 0, totalSum = 0;
                      for(; i < values.length; i++){
                          totalSum += values[i];
                      }
                      return totalSum;
                    }
                    db.query({map: map, reduce: reduce}, function(err, response) {
                      console.log('sum is ' + response.rows[0].value);
                    });
                  }
                  
                  function queryLargest() {
                    function map(doc) {
                      emit(doc._id, doc.number);
                    }
                    function reduce(keys, values, rereduce) {
                      // everything same as before (see querySum() above)
                      // so, this time we want the larger element of the values array
                  
                      // http://stackoverflow.com/a/1379560/1850609
                      return Math.max.apply(Math, values);
                    }
                    db.query({map: map, reduce: reduce}, function(err, response) {
                      console.log('largest is ' + response.rows[0].value);
                    });
                  }
                  
                  function querySmallest() {
                    function map(doc) {
                      emit(doc._id, doc.number);
                    }
                    function reduce(keys, values, rereduce) {
                      // all the same... now the looking for the min
                      return Math.min.apply(Math, values);
                    }
                    db.query({map: map, reduce: reduce}, function(err, response) {
                      console.log('smallest is ' + response.rows[0].value);
                    });
                  }
                  
                  function queryAverage() {
                    function map(doc) {
                      emit(doc._id, doc.number);
                    }
                    function reduce(keys, values, rereduce) {
                      // now simply calculating the average
                      var i = 0, totalSum = 0;
                      for(; i < values.length; i++){
                          totalSum += values[i];
                      }
                      return totalSum/values.length;
                    }
                    db.query({map: map, reduce: reduce}, function(err, response) {
                      console.log('average is ' + response.rows[0].value);
                    });
                  }
                  

                  注意:這只是一種方法.還有其他幾種可能性(不將 ID 作為鍵發(fā)出,使用組和不同的 reduce 函數(shù),使用內(nèi)置的 reduce 函數(shù),例如 _sum,...),我只是認(rèn)為一般來說這是更簡單的選擇.

                  Note: This is just one way to do it. There are several other possibilities (not emitting IDs as keys, using groups and different reduce functions, using built-in reduce functions, such as _sum, ...), I just thought this was the simpler alternative generally speaking.

                  這篇關(guān)于如何在 PouchDB 上模擬聚合函數(shù) avg、sum、max、min 和 count?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內(nèi)部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標(biāo)記群集圖標(biāo)顏色,繼承其余默認(rèn) CSS 屬性)
                  Trigger click on leaflet marker(觸發(fā)點擊傳單標(biāo)記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認(rèn)加載磁貼顏色?)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側(cè)邊欄)
                  Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在彈出窗口中獲取標(biāo)記的緯度和經(jīng)度)

                  <small id='FG1iH'></small><noframes id='FG1iH'>

                  1. <i id='FG1iH'><tr id='FG1iH'><dt id='FG1iH'><q id='FG1iH'><span id='FG1iH'><b id='FG1iH'><form id='FG1iH'><ins id='FG1iH'></ins><ul id='FG1iH'></ul><sub id='FG1iH'></sub></form><legend id='FG1iH'></legend><bdo id='FG1iH'><pre id='FG1iH'><center id='FG1iH'></center></pre></bdo></b><th id='FG1iH'></th></span></q></dt></tr></i><div class="0oce2my" id='FG1iH'><tfoot id='FG1iH'></tfoot><dl id='FG1iH'><fieldset id='FG1iH'></fieldset></dl></div>

                      <bdo id='FG1iH'></bdo><ul id='FG1iH'></ul>
                      <tfoot id='FG1iH'></tfoot>
                        <tbody id='FG1iH'></tbody>

                        <legend id='FG1iH'><style id='FG1iH'><dir id='FG1iH'><q id='FG1iH'></q></dir></style></legend>
                            主站蜘蛛池模板: 篮球地板厂家_舞台木地板品牌_体育运动地板厂家_凯洁地板 | 郑州外墙清洗_郑州玻璃幕墙清洗_郑州开荒保洁-河南三恒清洗服务有限公司 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | 都江堰招聘网-都江堰人才网 都江堰人事人才网 都江堰人才招聘网 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | 仿古建筑设计-仿古建筑施工-仿古建筑公司-汉匠古建筑设计院 | 儿童语言障碍训练-武汉优佳加感统文化发展有限公司 | 昆山PCB加工_SMT贴片_PCB抄板_线路板焊接加工-昆山腾宸电子科技有限公司 | 水成膜泡沫灭火剂_氟蛋白泡沫液_河南新乡骏华消防科技厂家 | HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 拖链电缆_柔性电缆_伺服电缆_坦克链电缆-深圳市顺电工业电缆有限公司 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 常州企业采购平台_常州MRO采购公司_常州米孚机电设备有限公司 | 金属波纹补偿器厂家_不锈钢膨胀节价格_非金属伸缩节定制-庆达补偿器 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | 翅片管换热器「型号全」_厂家-淄博鑫科环保 | 新型游乐设备,360大摆锤游乐设备「诚信厂家」-山东方鑫游乐设备 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 成都离婚律师|成都结婚律师|成都离婚财产分割律师|成都律师-成都离婚律师网 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 滚塑PE壳体-PE塑料浮球-警示PE浮筒-宁波君益塑业有限公司 | 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 水平筛厂家-三轴椭圆水平振动筛-泥沙震动筛设备_山东奥凯诺矿机 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 仓储笼_金属箱租赁_循环包装_铁网箱_蝴蝶笼租赁_酷龙仓储笼租赁 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 智能风向风速仪,风速告警仪,数字温湿仪,综合气象仪(气象五要素)-上海风云气象仪器有限公司 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | 自动售货机_无人售货机_专业的自动售货机运营商_免费投放售货机-广州富宏主官网 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | PCB厂|线路板厂|深圳线路板厂|软硬结合板厂|电路板生产厂家|线路板|深圳电路板厂家|铝基板厂家|深联电路-专业生产PCB研发制造 | YT保温材料_YT无机保温砂浆_外墙保温材料_南阳银通节能建材高新技术开发有限公司 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 航拍_专业的无人机航拍摄影门户社区网站_航拍网 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 拉伸膜,PE缠绕膜,打包带,封箱胶带,包装膜厂家-东莞宏展包装 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 |