开发者

how to introspect a couchdb document for its set of fields via couchdb-python

开发者 https://www.devze.com 2023-01-04 05:38 出处:网络
How can I get the fields for a couchdb document?I\'m thinking of how to use couchdb-python, and often will not know the complete set of fields for a document. I haven\'t seen anything about how to int

How can I get the fields for a couchdb document? I'm thinking of how to use couchdb-python, and often will not know the complete set of fields for a document. I haven't seen anything about how to introspect a d开发者_如何转开发ocument in the docs. What's the best way? If the document was a python object I would query object.__dict__ for its attributes.


.keys() returns a list of field names.

db = server['test']
for doc in db:
    print doc
    for key in db[doc].keys():
        print key

You should get the doc id, followed by the fields.

0

精彩评论

暂无评论...
验证码 换一张
取 消