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
Asked
Active
Viewed 561 times
2 Answers
2
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 + "\"}}");

Dharman
- 30,962
- 25
- 85
- 135

Jonas Kreusch
- 316
- 1
- 15
1
Save your data in JSON format, and then later passon 'couch db' query to this method to get answer.

Siva
- 598
- 3
- 11