cansado2930
cansado2930

Reputation: 339

how to do a query in order to get all elements on hyperledge fabric?

I have developed with "go" the chaincode (for hyperledge fabric) that has user profiles and items. I have learnt to do CRUD with a item & user, but I don't know how I could get all items or users without filters. Could you help me?

Thank you

Upvotes: 1

Views: 578

Answers (1)

cansado2930
cansado2930

Reputation: 339

There aren't methods for this, but you can add index with name of class and the id of object, and then you can return all objects with search the prefix of index, the class name. This is to create index

indexName := "Contract~Zone~ContractID"
colorNameIndexKey, err := stub.CreateCompositeKey(indexName, []string{"ContractPending", contractJSON.ZoneName, contractJSON.ContractID})

This is to search

contractResultsIterator, err := stub.GetStateByPartialCompositeKey("Contract~Zone~ContractID", []string{"Contract"})

Upvotes: 2

Related Questions