1

I have a database with around 2 million documents. This database contains a lot of duplicate documents. I wrote a map reduce function in CouchDB-Futon, which removes the duplicates. Now I want to get the values of this view in my python script.

import cloudant

account = cloudant.Account('Cricket-Harvestor')
db = account.database('Cricket-Analysis')
# view = Over here I want to reference the view I created in CouchDB futon.
for doc in view:
  # and so does this!
  print doc

Could someone please guide me over here? I have also referred below url:

https://pythonhosted.org/CouchDB/mapping.html

This uses couchdb-python library. I am creating and storing documents using the same library. But it seems to not serve purpose in getting data out of multiple documents from a view, which was created on CouchDB-Futon.

1 Answer 1

1

Your example code is using the Cloudant Python library.

Here is a similar example of querying a view on the Cloudant education account's animaldb database:

import cloudant
account = cloudant.Account('education')
db = account.database('animaldb')

doc = db.design('views101')  
view = doc.view('latin_name_jssum?reduce=false')

for doc in view:
   print doc

This outputs:

{u'value': 19, u'id': u'kookaburra', u'key': u'Dacelo novaeguineae'}
{u'value': 19, u'id': u'snipe', u'key': u'Gallinago gallinago'}
{u'value': 10, u'id': u'llama', u'key': u'Lama glama'}
{u'value': 11, u'id': u'badger', u'key': u'Meles meles'}
{u'value': 16, u'id': u'aardvark', u'key': u'Orycteropus afer'}

You can see the raw json response from the view at this url using curl or with your browser.

Here is the curl version:

snowch$ curl https://education.cloudant.com/animaldb/_design/views101/_view/latin_name_jssum?reduce=false
{"total_rows":5,"offset":0,"rows":[
   {"id":"kookaburra","key":"Dacelo novaeguineae","value":19},
   {"id":"snipe","key":"Gallinago gallinago","value":19},
   {"id":"llama","key":"Lama glama","value":10},
   {"id":"badger","key":"Meles meles","value":11},
   {"id":"aardvark","key":"Orycteropus afer","value":16}
]}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.