Hyperledger Fabric使用Go SDK将交易存储在CouchDB中

I am trying to integrate CouchDB as the statedb for my Hyperledger network, but am having trouble passing the values into the putState function (go sdk) to update the state.

The documentation says that a 'state' configuration needs to be added to the core.yaml file. However, this file does not exist in balance-transfer, and so I have modified the network-config.yaml file with the stateDatabase being couchdb instead of goleveldb, like below:

state:
  stateDatabase: CouchDB
  couchDBConfig:
  couchDBAddress: https://localhost:5984
  username:
  password:
  maxRetries: 3
  maxRetriesOnStartup: 10
  requestTimeout: 35s
  queryLimit: 10000

I have set up the configuration for a couchdb docker container for each peer in the docker-compose-couch.yaml file:

couchdb0:
  container_name: peer0.org1.couchdb
  image: hyperledger/fabric-couchdb
  environment:
    - COUCHDB_USER=
    - COUCHDB_PASSWORD=
  ports:
    - "5984:5984"

I have added the following parameters for each peer, so that the couchdb address for the peer points to the container created above.

CORE_LEDGER_STATE_STATEDATABASE=couchdb
CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984

Based on this, the couchdb docker containers all run fine, and port 5984 has the relevant databases created by the chaincode. What I am struggling with getting the values of a putState() request in the chaincode to appear. The go-sdk documentation outlines that putState requires a key (string) and value (json bytes array).

For example, if I submit a new transaction, the transaction will show up in couchdb under the db named mychannel_mycc with the ID that I specified, but none of the values that I passed as a json byte array went through. The document in couchdb looks like this:

{
  "_id": "000000000",
  "_rev": "1-6fab10bceb44087355a55b0bdc9bd9a4",
  "~version": "\u0000CgMBAwA=",
  "_attachments": {
    "valueBytes": {
      "content_type": "application/octet-stream",
      "revpos": 1,
      "digest": "md5-caYFgf07HPDwskuoN1DySg==",
      "length": 338,
      "stub": true
    }
  }
}

How can I ensure that my json object is passed through into the couchdb document?

I figured out that the issue is to do with the format of the JSON when it is passed into putState(). I was passing an array of JSON objects, rather than the JSON itself. If an invalid JSON is passed through the function, the data in CouchDB is reflected as an attachment rather than the JSON itself.

This is what I was originally passing through:

[{"name": "doe", "age": "20"}]

When I should have passed:

{"name": "doe", "age": "20"}

I also discovered that everything inside the JSON object had to be a string. So "age" has to be in quotes, rather than as an int.