【问题标题】:How to apply a pagination on array of objects in couchdb using hyperledger fabric?如何使用超级账本结构对 couchdb 中的对象数组应用分页?
【发布时间】:2021-02-26 12:07:43
【问题描述】:
  {
      "_id": "usq",
      "_rev": "5-f8e9a8853b15f0270df94c1ae71323216",
      "transactions": [
        {
          "admin_notification": [],
          "admin_status": "pending",
          "payment_amount_usd": "1",
          "sp_tx_datetime": "Feb 26, 2021, 12:22 PM",
          "sp_tx_hash": "pi_tx1",
          "sp_tx_status": "succeeded",
          "sp_tx_toAddress": "Admin",
          "tx_admin_dateTime": "-",
          "user_buyplan_days": "7 Days"
        },
        {
          "admin_notification": [],
          "admin_status": "pending",
          "payment_amount_usd": "2",
          "sp_tx_datetime": "Feb 26, 2021, 4:09 PM",
          "sp_tx_hash": "pi_tx2",
          "sp_tx_status": "succeeded",
          "sp_tx_toAddress": "Admin",
          "tx_admin_dateTime": "-",
          "user_buyplan_days": "7 Days"
        },
        {
          "admin_notification": [],
          "admin_status": "pending",
          "payment_amount_usd": "1",
          "sp_tx_datetime": "Feb 26, 2021, 12:22 PM",
          "sp_tx_hash": "pi_tx3",
          "sp_tx_status": "succeeded",
          "sp_tx_toAddress": "Admin",
          "tx_admin_dateTime": "-",
          "user_buyplan_days": "7 Days"
        }
      ],
      "user_email": "s@mail.com",
      "user_fName": "Sam",
      "user_id": "user_2304354",
      "user_lName": "Smith",
      "user_password": "Abc@123456",
      "user_type": "user",
      "~version": "CgMBFgA="
    }

在这里,我第一次只想要 2 笔交易而不是接下来的交易。所以我使用了 getQueryResultWithPagination 方法,但它不适用于单个对象。所以我创建了 CouchDB 的视图。

"views": {
    "tx-view": {
      "map": "function (doc) {if(doc.transactions.length > 0) {          emit(doc.transactions); }}"
    },
    "tx-view-2": {
      "map": "function (doc) { if(doc.transactions.length > 0) {      doc.transactions.forEach(function (tag) {    emit(doc.user_id, tag);  });}}"
    }
  },

我可以将此视图添加到链代码查询方法中并为其创建事务吗? 我该如何解决这个问题?

【问题讨论】:

    标签: couchdb hyperledger-fabric ibm-blockchain ibp-vscode-extension


    【解决方案1】:

    您是否尝试过查看此示例合同和应用程序? https://github.com/hyperledger/fabric-samples/tree/master/asset-transfer-ledger-queries

    【讨论】:

    • 感谢您的回复,是的,我试过了!但它也对特定文档(对象)应用分页,而不是在对象内部的数组中。如果可能的话,你能帮我吗?
    • 恐怕目前不可能
    猜你喜欢
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多