刪除/收回数据需要特別指定 action 為 delete,所有有 ref 的其他地方也會一併被移除。
因为在区块链 DB 上,所以往回找数据都还是会找到,只是对于当前最新数据状态已经移除。
删除一样是在 id 处用两个来指定:[ <predicate>
, <object>
]
[
{
"_id":[
"user/wallet", // predicate
"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bc" // object
],
"_action": "delete"
}
]
cURL 指令:
# linux
curl -H "Accept: application/json" -X POST -d '[{"_id":["user\\/wallet","0x7EA1EaA27b313D04D359bF3e654FE927376e31Bc"],"_action":"delete"}]' <http://13.114.145.25/fdb/seedao/testing/transact>
# windows
curl -H "Accept: application/json" -X POST -d "[{\\"_id\\":[\\"user\\/wallet\\",\\"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bc\\"],\\"_action\\":\\"delete\\"}]" <http://13.114.145.25/fdb/seedao/testing/transact>
这时候查询就找不到了:
[
{
"_id":351843720888323,
"user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3",
"user/email":"[email protected]"
},
{
"_id":351843720888321,
"user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd2",
"user/email":"[email protected]"
},
{
"_id":351843720888320,
"user/wallet":"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bb",
"user/email":"[email protected]"
}
]
如果是要删除某一个 data 的某个 predicate 的值,可以使用 null
[
{
"_id":[
"user/wallet",
"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3"
],
"email": null
}
]
cURL 指令:
# linux
curl -H "Accept: application/json" -X POST -d '[{"_id":["user/wallet","0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3"],"email":null}]' <http://13.114.145.25/fdb/seedao/testing/transact>
# windows
curl -H "Accept: application/json" -X POST -d "[{\\"_id\\":[\\"user/wallet\\",\\"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3\\"],\\"email\\":null}]" <http://13.114.145.25/fdb/seedao/testing/transact>
我们再看数据就会发现指定 wallet 的 email 为空:
[
{
"_id":351843720888323,
"user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3"
// email 不见了
},
{
"_id":351843720888321,
"user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd2",
"user/email":"[email protected]"
},
{
"_id":351843720888320,
"user/wallet":"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bb",
"user/email":"[email protected]"
}
]