Tools, FAQ, Tutorials:
Query CouchDB Container API Directly
How to query CouchDB Container API directly?
✍: FYIcenter.com
If you are running BYFN (Build Your First Network) with the CouchDB option, the World State of each peer node is stored a CouchDB server running as Docker container.
The CouchDB server supports a REST API interface at the local port 4369, which is mapped to another port of the hosting system.
You can use "curl" command to query the CouchDB REST API directly, if it has no user name and password protection.
1. List all CouchDB containers:
$ docker ps --all | grep couchdb hyperledger/fabric-couchdb 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb0 hyperledger/fabric-couchdb 4369/tcp, 9100/tcp, 0.0.0.0:6984->5984/tcp couchdb1 hyperledger/fabric-couchdb 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp couchdb2 hyperledger/fabric-couchdb 4369/tcp, 9100/tcp, 0.0.0.0:8984->5984/tcp couchdb3
As you can see, 4 CouchDB API ports are mapped to 5984, 6984, 7984, and 8984 of the local hosting system.
2. Query couchdb0 container, which should be connected peer0.org1. After connecting to the 5984 port, you need to enter the "GET ..." command by 2 "Enter" keys.
$ curl http://localhost:5984/ {"couchdb":"Welcome","version":"2.2.0","git_sha":"2a16ec4", "features":["pluggable-storage-engines","scheduler"], "vendor":{"name":"The Apache Software Foundation"}}
3. Get all databases on the server:
$ curl http://localhost:5984/_all_dbs ["_replicator","_users", "mychannel_","mychannel__lifecycle","mychannel_lscc", "mychannel_mycc"]
As you can see, there 3 databases for "mychannel" channel and 1 database for "mycc" chaincode running on "mychannel":
4. Get all documents from the "mychannel_mycc" database:
$ curl http://localhost:5984/mychannel_mycc/_all_docs {"total_rows":2,"offset":0,"rows":[ {"id":"a","key":"a","value":{"rev":"2-f5911b70345a8fe9b45e699f2aebb2b8"}}, {"id":"b","key":"b","value":{"rev":"2-f2e091417a9884e1f5ef483ae2b71093"}} ]}
5. Get the content of document "a":
$ curl http://localhost:5984/mychannel_mycc/a { "_id": "a", "_rev": "2-f5911b70345a8fe9b45e699f2aebb2b8", "~version": "\u0000CgMBBAA=", "_attachments": { "valueBytes": { "content_type": "application\/octet-stream", "revpos": 2, "digest": "md5-qpvq4\/JGMCgu7WtvFu5zbg==", "length": 2, "stub": true } } }
⇒ CouchDB Server Admin Web Portal
⇐ Peer and CouchDB Container Dependency
2020-06-08, 1522🔥, 0💬
Popular Posts:
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not acce...
How to include additional claims in Azure AD v2.0 id_tokens? If you want to include additional claim...
How To Convert a Character to an ASCII Value? If you want to convert characters to ASCII values, you...
How to create Hello-3.1.epub with WinRAR? I have all required files to create Hello-3.1.epub. To cre...
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...