0

I am developing a couchapp. I have documents that contains a field called tags, and I am trying to retrieve the unique tags among all the docs. My map/reduce function is as follows:

map.js

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

reduce.js

function(keys,values,rereduce){
    return sum(values);
}

And the output returned is the count of all the tags. Where am I going wrong?

swaroopsm
  • 1,389
  • 4
  • 18
  • 34

1 Answers1

0

If you want a list of all tags you don't need a reduce function. You need to call your view with the option group=true. So for example you call

http://localhost:5984/yourdb/views/tag_view?group=true

or with couch.js you can do

$.couch.db.view('your_view', {data: {"group": true}});

If you look at the documentation you see that you define ajaxOptions for the request in the same way you define them for normal ajax request in jQuery. So you just use the data option documented here

For further information see CouchDB Wiki Grouping.

dignifiedquire
  • 1,360
  • 9
  • 14
  • I am using the jquery.couch.js plugin. So how do I call this in it: I tried $.couch.db($db).view("app/my_view?group=true") but dint work. – swaroopsm Jul 31 '12 at 15:30