In hyperledger fabric chaincode I want to check whether a key already exists or not, so that if another record with the same key is tried to be stored in the ledger, it should show up error. What is the best way to do this in fabric?
In hyperledger fabric chaincode I want to check whether a key already exists or not, so that if another record with the same key is tried to be stored in the ledger, it should show up error. What is the best way to do this in fabric?
Use
stub.GetState(key)
and check if it returns any value. The key is indexed so it will not be so time-consuming even using couchdb. The history is maintained by levelDB that is very performative for key queries.
But a quick tip, avoid couchdb, try to design you chaincode to use composite key and dont use rich queries if you want more performance and throughput.
Hope it helps.