mathk
mathk

Reputation: 8123

Reduce is not counting by key

I am using couchbase 3.0 and playing with the beer-sample data.

I have create a view with map being:

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

This give the following output:

{"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}
]
}

When selecting the top 10.

Now I would like to count the number of beer per category. So I decide to add the builtin reduce _count.

Unfortunatly the output is not the expected one but rather :

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

Why do I have key set to null and not being the doc.category?

Upvotes: 1

Views: 36

Answers (1)

mathk
mathk

Reputation: 8123

I realized that I have forgot to add group parameter when querying the view. With that in place everything work fine.

Upvotes: 1

Related Questions