famar
famar

Reputation: 33

Hyperledger Fabric java how to use getQueryResult()

I'm trying to use the getQueryResult() method in a transaction but i'm not able to understand what type of string i have to pass in the method. I have an asset composed by and id, name, surname and an hash. I want to verify that the hash doesn't alreaty exists in the ledger. The underlying database is couchdb. All the string i used returned me an error. Could someone help me to use the right syntax? Thank you

Upvotes: 1

Views: 745

Answers (2)

Jonas Kreusch
Jonas Kreusch

Reputation: 356

The string you have to pass must be in couchdb selector syntax, see here: https://docs.couchdb.org/en/latest/api/database/find.html#find-selectors The hyperledger fabric tutorial mentions this here: https://hyperledger-fabric.readthedocs.io/en/release-2.2/couchdb_tutorial.html#build-the-query-in-chaincode So for example if your asset has the field "hash" you could query like so:

String queryHash;
QueryResultsIterator<KeyValue> results = stub.getQueryResult("{\"selector\":{\"hash\":\"" + queryHash + "\"}}");

Upvotes: 2

Siva
Siva

Reputation: 768

Save your data in JSON format, and then later passon 'couch db' query to this method to get answer.

Upvotes: 1

Related Questions