title: How to get transaction history on a particular key in Hyperledger Fabric?
body: <p>I have a Hyperledger Fabric network with multiple peers with corresponding StateDB (CouchDB) and I have given CORE_LEDGER_HISTORY_ENABLEHISTORYDATABASE=true in all peer configuration under docker compose file. The idea that I shall be able to retrieve the update history of a record basis the key. The key here is a trade number and whenever any attribute of Trade gets updated, I do see update happening in CouchDB as I see increase in revision value. Now, in my chaincode function, have added below snippet of code (sample code for now)</p>
  
  <p>_, args := stub.GetFunctionAndParameters()</p>
  
  <pre><code>tradeNumber := args[1]
  
  historyIer, err := stub.GetHistoryForKey(tradeNumber)
  
  if err != nil {
      fmt.Println(err.Error())
      return shim.Error(err.Error())
  }
  
  if historyIer.HasNext() {
      modification, err := historyIer.Next()
      if err != nil {
          fmt.Println(err.Error())
          return shim.Error(err.Error())
  }
  fmt.Println("Returning information about", string(modification.Value))
  </code></pre>
  
  <p>}
      return shim.Success(nil)</p>
  
  <p>However, everytime I check chaincode container, it prints only the last value of Trade than the number of updates it has gone through, can anybody please let me know what wrong am I doing here?</p>