How to check if the key has already existed in Hyperledger 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?