Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple CouchDB Document fetch with couchdb-python

Tags:

python

couchdb

How to fetch multiple documents from CouchDB, in particular with couchdb-python?

like image 256
dnolen Avatar asked Oct 28 '09 20:10

dnolen


1 Answers

Easiest way is to pass a include_docs=True arg to Database.view. Each row of the results will include the doc. e.g.

>>> db = couchdb.Database('http://localhost:5984/test')
>>> rows = db.view('_all_docs', keys=['docid1', 'docid2', 'missing'], include_docs=True)
>>> docs = [row.doc for row in rows]
>>> docs
[<Document 'docid1'@'...' {}>, <Document 'docid2'@'...' {}>, None]

Note that a row's doc will be None if the document does not exist.

This works with any view - just provide a list of keys suitable to the view.

like image 76
Matt Goodall Avatar answered Sep 25 '22 23:09

Matt Goodall