如何在couchdb使用超级账本结构的对象数组上应用分页?


{
"_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);  });}}"
}
},

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

你看过这份合同样本了吗?应用程序?https://github.com/hyperledger/fabric-samples/tree/master/asset-transfer-ledger-queries

最新更新