Alex A
Alex A

Reputation: 79

CouchDB Map/Reduce Error on what seems to be a simple query

I have a VERY simple map/reduce I need to accomplish. I need to get a list of all unique docType values in our database. However, as soon as I add the Reduce function, I get the following error:

"Expression does not eval to a function." etc.

I'm following the examples from the CouchDB Cookbook and WIKI, and this is stupid simple, so I'm not sure why it's failing.

The map code is as follows:

function(doc){ if(doc.docType) emit(doc.docType,1); }

This returns every docType without any distinct grouping yet.

The reduce is direct from the samples I've seen:

function reduce(key,values){ return null; }

This immediately throws the error above... What am I missing?

Any help would be greatly appreciated.

Thanks!

Upvotes: 0

Views: 90

Answers (1)

Dominic Barnes
Dominic Barnes

Reputation: 28429

When adding handler functions in CouchDB, you should not include a function identifier, treat it as you would an anonymous function. (it has to do with how CouchDB evals your string into a JS function, of which I do not know the specifics off-hand)

So, for your reduce function, leave off the reduce identifier.

function (keys, values) {
  return null;
}

Upvotes: 1

Related Questions