【问题标题】:Function Reduce CouchDB for this case此案例的功能减少 CouchDB
【发布时间】:2016-05-15 16:11:02
【问题描述】:

我在 CouchDB 中有一个这种格式的文档:

{ 
      "box": 1, 
      "store": "New City", 
       "types": "sales"
}

我有以下地图功能:

function(doc) {
  if (doc.types == "sales") {
   if ( doc.box != null && doc.box != false)
    {
     emit(doc.box, doc.store);
     }
   }
}

我想显示每个商店的盒子数量,但我无法创建 reduce 函数。

【问题讨论】:

    标签: javascript mapreduce couchdb database nosql


    【解决方案1】:

    如果您将 store 作为 key 并将 box 的数量作为 value,那么内置的 reduce 函数 _sum(只需将 _sum 作为 reduce 函数)就可以完成这项工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2020-11-01
      • 2019-09-10
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      相关资源
      最近更新 更多