Working with bookmarks #bookmark #fabric-chaincode


Sumitvedpathak@...
 

Hi Guys,
I am quite new to Fabric, and in a learning stage. I am trying to have some hands on bookmark in pagination. But it is really giving me tough time to get the bookmarks in the results.
What i am trying is in below code

My couchdb index file 

My query is as below.

When i use only iterator as a return object then i am able to get the result, but when used with {iterator, metadata} to get the bookmark, it complains about  asyncIterator error.
Peer logs shows


Not sure, what i am missing here. Any help would appreciate.

Thanks,
Sumit


Pratik Sanjay Patil <pratikspatil024@...>
 

Hi,

If you want to get the next bookmark then the below code example should work:

```
const temp = await ctx.stub.getStateByRangeWithPagination("", "", pageSize, bookmark);
// bookmark to get the next page
let next_bookmark= temp.metadata.bookmark;
```

Thanks,
Pratik Sanjay Patil


Kavin Arumugam
 

Hi Sumit,

Hyperledger Fabric Samples having examples for Bookmarks.
Please find the sample code below. Entire Chaincode can be found here
func (t *SimpleChaincode) QueryAssetsWithPagination(ctx contractapi.TransactionContextInterface, queryString string, pageSize int, bookmark string) (*PaginatedQueryResult, error) {

	return getQueryResultForQueryStringWithPagination(ctx, queryString, int32(pageSize), bookmark)
}

// getQueryResultForQueryStringWithPagination executes the passed in query string with
// pagination info. The result set is built and returned as a byte array containing the JSON results.
func getQueryResultForQueryStringWithPagination(ctx contractapi.TransactionContextInterface, queryString string, pageSize int32, bookmark string) (*PaginatedQueryResult, error) {

	resultsIterator, responseMetadata, err := ctx.GetStub().GetQueryResultWithPagination(queryString, pageSize, bookmark)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	assets, err := constructQueryResponseFromIterator(resultsIterator)
	if err != nil {
		return nil, err
	}

	return &PaginatedQueryResult{
		Records:             assets,
		FetchedRecordsCount: responseMetadata.FetchedRecordsCount,
		Bookmark:            responseMetadata.Bookmark,
	}, nil
}


Thanks & Regards
Kavin Arumugam
Mobile: +91 7373 36 86 36
LinkedIn: @karthikkavina


On Thu, Oct 14, 2021 at 3:59 PM <Sumitvedpathak@...> wrote:
Hi Guys,
I am quite new to Fabric, and in a learning stage. I am trying to have some hands on bookmark in pagination. But it is really giving me tough time to get the bookmarks in the results.
What i am trying is in below code

My couchdb index file 

My query is as below.

When i use only iterator as a return object then i am able to get the result, but when used with {iterator, metadata} to get the bookmark, it complains about  asyncIterator error.
Peer logs shows


Not sure, what i am missing here. Any help would appreciate.

Thanks,
Sumit