如何在couchdb中使用Hyperledger Fabric对对象数组进行分页?

b4lqfgs4  于 2022-12-09  发布在  CouchDB
关注(0)|答案(1)|浏览(159)
{
      "_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);  });}}"
    }
  },

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

相关问题