开发者

null key in from map/reduce result in couchdb

开发者 https://www.devze.com 2023-03-08 01:32 出处:网络
For some reason I\'m only getting a null key from map/reduce result in couchdb on mac Result: {\"rows\":[

For some reason I'm only getting a null key from map/reduce result in couchdb on mac

Result:

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

Im using couchapp v8.1 and couchdb v1.0.2

My map function is:

function(doc) {
    emit(doc.doc_type, 1);
}

My reduce function is:

function(key, values, rereducer) {
  return sum(values);
}

result I was expecting:

{"rows":[
{"key":"type1","value":22}
{"key":"type2","value":32}
{"key":"type3","value开发者_运维技巧":25}
 //snip snip
]}

Any idea where I went wrong?


Just to save newbies the pain I've been through to get to this answer, please look at the group parameter of the _view API which is explained in more detail in the CouchDB guide.

I just add ?group=true to my url, and the reduce result was grouped as expected the default behavior is that reduce will spit out a single value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号