减少不计算密钥

时间:2016-01-04 16:57:01

标签: mapreduce couchbase

我正在使用couchbase 3.0并使用啤酒样本数据。

我创建了一个地图为:

的视图
function (doc, meta) {
  if (doc.category && doc.abv) {
    emit(doc.category, doc.abv);
  }
}

这给出了以下输出:

{"total_rows":2397,"rows":[
{"id":"21st_amendment_brewery_cafe-watermelon_wheat","key":"Belgian and French Ale","value":5.5},
{"id":"3_fonteinen_brouwerij_ambachtelijke_geuzestekerij-drie_fonteinen_kriek","key":"Belgian and French Ale","value":5},
{"id":"3_fonteinen_brouwerij_ambachtelijke_geuzestekerij-oude_geuze","key":"Belgian and French Ale","value":6},
{"id":"512_brewing_company-512_wit","key":"Belgian and French Ale","value":5.2},
{"id":"512_brewing_company-one","key":"Belgian and French Ale","value":8},
{"id":"abbaye_de_maredsous-10","key":"Belgian and French Ale","value":10},
{"id":"abbaye_de_maredsous-8","key":"Belgian and French Ale","value":8},
{"id":"abbaye_notre_dame_du_st_remy-rochefort_10","key":"Belgian and French Ale","value":11.3},
{"id":"abita_brewing_company-satsuma_harvest_wit","key":"Belgian and French Ale","value":5.1},
{"id":"affligem_brouwerij-affligem_dubbel","key":"Belgian and French Ale","value":6.8}
]
}

选择前10名时。

现在我想计算每个类别的啤酒数量。所以我决定添加内置的reduce _count

不幸的是,输出不是预期的输出,而是:

{"rows":[
 {"key":null,"value":2397}
 ]
}

为什么我将密钥设置为null而不是doc.category

1 个答案:

答案 0 :(得分:1)

我意识到在查询视图时忘记添加组参数。有了它,一切都很好。