Built in Reduce Functions from the Client

Is it possible to add a built in reduce function to a view via the client? When I try to do this, I get the following:

{“error”:“invalid_design_document”,“reason”:“Syntax error in the reduce function of the view `exceptions’: ReferenceError: _count is not defined”}

Here’s my map/reduce on that particular view:

{
  "map": "function (doc, meta) {if(doc.type === "LogItem"){ emit([doc.originatingSystem, doc.level, doc.timeStamp], null); }}",
  "reduce": "_count"
}

I need to be able to avoid going into the admin console to add a built-in reduce to a view.

Any help would be appreciated. Thanks!

I figured out the problem. If anyone else has this issue, it’s because reduce in the json needs to be specified exactly like

"reduce" : "_count"

My problem was that there were two new line characters, so mine looked like

"reduce" : "\n_count\n"

Therefore, couchbase tries to validate “\n_count\n” as valid javascript (which it is not).

2 Likes

@joshboley -

Thanks for posting the resolution!

-Jeff