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="tbrhxrj" id='XMKN1'><tfoot id='XMKN1'></tfoot><dl id='XMKN1'><fieldset id='XMKN1'></fieldset></dl></div>
      2. 如何在 PouchDB 上模擬聚合函數 avg、sum、max、min

        How to simulating the aggregate functions avg, sum, max, min, and count on PouchDB?(如何在 PouchDB 上模擬聚合函數 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="r7zld77" id='g8VPG'><tfoot id='g8VPG'></tfoot><dl id='g8VPG'><fieldset id='g8VPG'></fieldset></dl></div>

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

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

                  問題描述

                  有誰知道如何在 PouchDB 數據庫上創建聚合函數,例如 avg、sum、max 和 min.我創建了一個簡單的應用程序來測試 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.

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

                  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 函數 來自 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.

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

                  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 作為鍵發出,使用組和不同的 reduce 函數,使用內置的 reduce 函數,例如 _sum,...),我只是認為一般來說這是更簡單的選擇.

                  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.

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

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

                  相關文檔推薦

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

                  <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="jbfhbvv" 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>
                            主站蜘蛛池模板: 12cr1mov无缝钢管切割-15crmog无缝钢管切割-40cr无缝钢管切割-42crmo无缝钢管切割-Q345B无缝钢管切割-45#无缝钢管切割 - 聊城宽达钢管有限公司 | 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 扫地车厂家-山西洗地机-太原电动扫地车「大同朔州吕梁晋中忻州长治晋城洗地机」山西锦力环保科技有限公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 祝融环境-地源热泵多恒系统高新技术企业,舒适生活环境缔造者! | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 空压机网_《压缩机》杂志 | 二手Sciex液质联用仪-岛津气质联用仪-二手安捷伦气质联用仪-上海隐智科学仪器有限公司 | 对夹式止回阀厂家,温州对夹式止回阀制造商--永嘉县润丰阀门有限公司 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 超声波焊接机_超音波熔接机_超声波塑焊机十大品牌_塑料超声波焊接设备厂家 | QQ房产导航-免费收录优秀房地产网站_房地产信息网 | 河南砖机首页-全自动液压免烧砖机,小型砌块水泥砖机厂家[十年老厂] | 酒精检测棒,数显温湿度计,酒安酒精测试仪,酒精检测仪,呼气式酒精检测仪-郑州欧诺仪器有限公司 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 车件|铜件|车削件|车床加工|五金冲压件-PIN针,精密车件定制专业厂商【东莞品晔】 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器| 标策网-专注公司商业知识服务、助力企业发展 | 2025黄道吉日查询、吉时查询、老黄历查询平台- 黄道吉日查询网 | 云南标线|昆明划线|道路标线|交通标线-就选云南云路施工公司-云南云路科技有限公司 | 便携式表面粗糙度仪-彩屏硬度计-分体式粗糙度仪-北京凯达科仪科技有限公司 | 合同书格式和范文_合同书样本模板_电子版合同,找范文吧 | 苗木价格-苗木批发-沭阳苗木基地-沭阳花木-长之鸿园林苗木场 | 重庆网站建设,重庆网站设计,重庆网站制作,重庆seo,重庆做网站,重庆seo,重庆公众号运营,重庆小程序开发 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 标准品网_标准品信息网_【中检计量】 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | 钢格栅板_钢格板网_格栅板-做专业的热镀锌钢格栅板厂家-安平县迎瑞丝网制造有限公司 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 南京试剂|化学试剂|分析试剂|实验试剂|cas号查询-专业60年试剂销售企业 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 安徽免检低氮锅炉_合肥燃油锅炉_安徽蒸汽发生器_合肥燃气锅炉-合肥扬诺锅炉有限公司 | 超声波清洗机_超声波清洗机设备_超声波清洗机厂家_鼎泰恒胜 | 荣事达手推洗地机_洗地机厂家_驾驶式扫地机_工业清洁设备 | 贴板式电磁阀-不锈钢-气动上展式放料阀-上海弗雷西阀门有限公司 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 专业广州网站建设,微信小程序开发,一物一码和NFC应用开发、物联网、外贸商城、定制系统和APP开发【致茂网络】 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 |