Search code examples
javascriptgun

Can't delete a node from the root level


gun 0.8.8, Node.js-to-Node.js, Node.js-to-browser

Create a node (Node.js)

let node = gun.get(`watcher/f0de26c0-a29f-11e7-8661-154b982951a4`);
node.put({
  stats: {
    num: 13
  },
  name: 'trex'
});

Delete the node (Node.js)

node.put(null);

Check if the node exists (Node.js)

node.get('stats').val(function (v, k) {
  console.log('task', task);
  console.log('k:', k);
  console.log('v:', v);
});

The node and all its properties still exist!

task f0de26c0-a29f-11e7-8661-154b982951a4
k: stats
v: { _: { '#': 'j949102jDUdSklGduZh8', '>': { num: 1508926521878 } },
  num: 13 }

Check if the node exists (browser)

gun.get('watcher/f0de26c0-a29f-11e7-8661-154b982951a4').get('stats').val((v, k) => console.log(JSON.stringify(v)))
VM604:1 {"_":{"#":"j949102jDUdSklGduZh8",">":{"num":1508926521878}},"num":13}

Try to delete the node again (browser)

gun.get('watcher/f0de26c0-a29f-11e7-8661-154b982951a4').put(null)
gun.js:825 Data saved to the root level of the graph must be a node (an object), not a object of "null"!

Is it possible to delete a root level node completely?

Why there is no warning message when I try to delete it from Node.js?

What is the not root level?


Solution

  • The short answer is you can't. You can empty the node... gun.get( "rootNode" ).put( null );

    Or you can add a top layer node like 'dbRoot' and put everyone one layer deeper than the root.

    A way that might work...

    • Start a new gun instance that connects to the first, and does a map of all nodes except the one you want to delete.
    • Close both servers, move the data.json to the original one
    • Restart the server.