How to delete data in gun DB?

情到浓时终转凉″ 提交于 2019-12-07 00:21:07

问题


I have been developing some things and you know during early prototyping types and tables change quickly... it would be nice to cleanup the old data and start again in certain meshes.

For now I was using the example HTTP server so I deleted data.json; but I forgot the localStorage in the browser also needs to be cleared.

One might suppose you could put(null)

I asked on gitter and got

https://github.com/amark/gun/wiki/delete

except for deletes , lol, our excuse is "It works like your OS, when you delete >something it just gets tossed in the trash/recycle bin. That's all." better safe than sorry though

if you are trying to "delete" stuff because you messed up while developing >something, follow this three step process: 1) localStorage.clear() in every >browser tab you have up, 2) Crash the server and rm data.json, 3) restart >everything. You should then have a clean slate. Often times while I'm >devleoping something I put localStorage.clear() at the top of my code so I only >have to worry about clearing the server.


回答1:


Welcome to the gun community! Thanks for asking questions.

Yes, deleting data is most simply done with gun.put(null). Take:

var gun = Gun();
var users = gun.get('users');
users.put({alice: {name: 'alice'}, bob: {name: 'bob'}});
// now let's delete bob
users.path('bob').put(null);

If (as you mentioned in the question) however, you mean "delete data" as in wanting to clear out mistakes while developing your app. You'll want to do what you mentioned: localStorage.clear() in all browsers, crash the all servers and rm data.json.

For other developers, it might be useful to know that gun uses a type of tombstone method. You can't actually delete nodes themselves, they just get de-referenced, kinda like how your OS just moves files into a trash/recycle-bin. This tombstone method is very important in a distributed environment, such that the "delete" operation is replicated to every peer.

Thanks for answering your own question though! As always, if you get lost or need help hop on the https://gitter.im/amark/gun .



来源:https://stackoverflow.com/questions/37758618/how-to-delete-data-in-gun-db

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!