1

我希望能够使用 python API(或任何 API)获取可用于存储桶的视图列表。我该怎么做呢?

4

1 回答 1

1
import couchbase
from couchbase.rest_client import RestConnection
import json

server_info = { "ip" : "127.0.0.1", "port" : 8092, 
                "username" : "", 
                "password" : "", 
                "couchApiBase" :  "http://127.0.0.1:8092/" }
rest = RestConnection(server_info)

params = "startkey=\"_design\"&endkey=\"_design0\""
design_docs_uri = "http://%s:8091/couchBase/default/_all_docs?%s" % (server_info["ip"], params)

#not supported as public API
response, content = rest._http_request(design_docs_uri, 'GET', headers=rest._create_headers())
json_parsed = json.loads(content)

for row in json_parsed["rows"]:
    design_doc = row["key"].split("/")[1]

    print "Views for design doc: %s" % design_doc
    doc = rest.get_design_doc("default", design_doc)
    #get views element from dictionary
    for view in doc["views"]:
        print "\t%s" % view
于 2012-04-13T17:38:09.427 回答