0

A sample code let

keyIter = ctx.stub.getStateByPartialCompositeKey(this.name, strkey);
console.log("keyIter"+ keyIter);

I created composite keys via 2 keys and I am able to see the record in Couch DB. However while trying to get the entire list of all keys which matches the first key I do not get an iterable as per documentation. Pls share the results.

I am using VSE extension and working on IBM Blockchain Platform V0.3.0

Logs

keyIter[object Promise]
2019-02-28T23:22:22.132Z ERROR [contracts-spi/chaincodefromcontract.js]  
    {"message":"keyIter is not iterable","stack":"TypeError: keyIter is not iterable\n    at MyContract.query (/usr/local/src/lib/my-contract.js:42:25)\n    at ChaincodeFromContract.invokeFunctionality (/usr/local/src/node_modules/fabric-shim/lib/contract-spi/chaincodefromcontract.js:322:58)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)"}
2019-02-28T23:22:22.134Z ERROR [lib/handler.js] [mychannel-6323acf1]Calling chaincode Invoke() returned error response [TypeError: keyIter is not iterable]. Sending ERROR message back to peer
Harshit
  • 886
  • 7
  • 18
  • 1
    What is the value and type of 'strkey' - I think it should be an array of string. Have you tested by passing just an empty array? e.g. keyIter = ctx.stub.getStateByPartialCompositeKey(this.name, []); – R Thatcher Mar 01 '19 at 09:41
  • Hi , I tried the same but same error . Let me share the code and logs.async query(ctx, key) { console.log("key"+ key); console.info('querying for key: ' + key ); var strkey = [key]; console.log("strkey"+ strkey); console.log("this.name::"+ this.name,); let keyIter = await ctx.stub.getStateByPartialCompositeKey(this.name, []); console.log("keyIter"+ keyIter); for (const numkey of keyIter) { console.log("numkey::"+numkey); }} – Pankaj Tripathi Mar 01 '19 at 14:32
  • Logskey12 querying for key: 12 strkey12 this.name::MyContract keyIter[object Object] 2019-03-01T14:24:14.602Z ERROR [contracts-spi/chaincodefromcontract.js] {"message":"keyIter is not iterable","stack":"TypeError: keyIter is not iterable\n at MyContract.query (/usr/local/src/lib/my-contract.js:42:25)\n at \n at process._tickCallback (internal/process/next_tick.js:188:7)"} 2019-03-01T14:24:14.602Z ERROR [lib/handler.js] [mychannel-42373355]Calling chaincode Invoke() returned error response [TypeError: keyIter is not iterable]. Sending ERROR message back to peer – Pankaj Tripathi Mar 01 '19 at 14:34
  • This working fine after changing the iterator query code. while (true) { const res = await keyIter.next(); console.log("res.value:: "+ res.value); – Pankaj Tripathi Mar 01 '19 at 16:15

1 Answers1

0

PLease verify that this.name is the index name and it should be within double quotes . strkey refers to the composite key .

swarna
  • 51
  • 1
  • 1