简体   繁体   中英

How to apply a pagination on array of objects in couchdb using hyperledger fabric?

  {
      "_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="
    }

Here I want only 2 transactions at the first time than the next ones. So I have used getQueryResultWithPagination methods But It doesn't work on a single object. So I created a view of 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);  });}}"
    }
  },

Can I add this view into chaincode query method and create a transaction for the same? How do I resolve this?

Have you tried looking at this sample contract & application? https://github.com/hyperledger/fabric-samples/tree/master/asset-transfer-ledger-queries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM