ORDER BY not working in named query

老子叫甜甜 提交于 2019-12-06 05:35:41

For my network, I order the query returned from HistorianRecord by the timestamp:

query getAllHistorianRecords {
  description: "getTradeRelatedHistorianRecords"
  statement: 
    SELECT org.hyperledger.composer.system.HistorianRecord
      WHERE (transactionTimestamp > '0000-01-01T00:00:00.000Z')
        ORDER BY [transactionTimestamp ASC]
}

To make this ORDER BY statement work I had to create an index in CouchDB. If you used the scripts to create your fabric your database should be at http://localhost:5984/_utils/#database/composerchannel/_all_docs.

curl -X POST --header 'Content-Type: application/json' --header 
'Accept: application/json' -d '
{
  "index": {
    "fields": [
      {
        "data.transactionTimestamp": "asc"
      }
    ]
  },
  "type": "json"
}' 'http://localhost:5984/composerchannel/_index'

This curl will create an index that the query can use to enable ORDER BY

It looks like you need to define a sort index on your data types in CouchDB to use ORDER BY.

See this for details: https://github.com/hyperledger/composer/issues/1640

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!