dictionarycouchdbreducecouchapp

null key in from map/reduce result in couchdb


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?


Solution

  • 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.