Reputation: 29
I need to retrieve all docs with the specified field from couchdb, but only getting result from one document. But when I print it, all docs are showing
for item in db.view('_all_docs'):
doc = item.doc
_id = item['id']
f = open('retrieve.csv', 'w')
writer = csv.writer(f)
writer.writerow([_id])
Upvotes: 1
Views: 957
Reputation: 907
If you want to turn a CouchDB dataset into a CSV you could either use the CouchDB Show function if you just need to do it for one single document or the CouchDB List function if you need to do combine multiple documents.
http://docs.couchdb.org/en/2.1.2/ddocs/ddocs.html#show-functions
http://guide.couchdb.org/draft/show.html
http://guide.couchdb.org/draft/transforming.html
Upvotes: 0
Reputation: 29
to get all , the open file needs to be outside the loop
f = open('retrieve.csv', 'w')
writer = csv.writer(f)
for item in db.view('_all_docs'):
doc = item.doc
_id = item['id']
writer.writerow([_id])
Upvotes: 1