0
votes

I am trying to use map/reduce to find the duplication of the data in couchDB the map function is like this:

function(doc) {
   if(doc.coordinates) { 
       emit({
           twitter_id: doc.id_str, 
           text: doc.text,
           coordinates: doc.coordinates
       },1)};
   }
}

and the reduce function is:

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

I want to find the sum of the data in the same key, but it just add everything together and I get the result:

<Row key=None, value=1035>

Is that a problem of group? How can I set it to true?

1

1 Answers

0
votes

Assuming you're using the couchdb package from pypi, you'll need to pass a dictionary with all of the options you require to the view.

for example:

import couchdb

# the design doc and view name of the view you want to use
ddoc = "my_design_document"
view_name = "my_view"

#your server
server = couchdb.server("http://localhost:5984")
db = server["aCouchDatabase"]
#naming convention when passing a ddoc and view to the view method
view_string = ddoc +"/" + view_name
#query options
view_options = {"reduce": True,
                "group" : True,
                "group_level" : 2}
#call the view
results = db.view(view_string, view_options)

for row in results:
    #do something
    pass