How to delete a single node

Hi,
I just started learning Dgraph. I have an extremally simple question: how to delete a single node itself (not its affiliation with any other node)? Suppose I have
{
“uid”: “0x1”,
“name”: “Ben”
},
that is not connected to any other node - how to delete it?
I’ll tried something obvious
{
“delete”: [
{
“uid”: “0x1”
}
]
}
but that deletes connections to other nodes only, the node itself is still there. Despite the question simplicity, I couldn’t find any answer so far.
Thanks…

I was thinking there was more docs around DQL delete, but this is all I really see:

https://dgraph.io/docs/dql/mutations/uid-upsert/#bulk-delete-example

Looking back over a past discussion, I linked to a doc page that doesn’t seem to exist anymore. @MichelDiz do you know if this got moved somewhere? Would be worth a 301 at least please.

So in leue of not having that doc page I was looking for, let me try to briefly explain it here again.

Deletes in DQL work with three patterns (somewhat explained in the DQL Tour). You can delete a specific Subject-Predicate-Object (SPO), or delete all Subject-Predicate no matter the Object value assigned (SP*), or delete all predicates of a given Subject (S**).

In DQL these take the form of:

delete {
  # SPO
  <0x1> <name> "Ben" .
  # SP*
  <0x1> <name> * .
  # S**
  <0x1> * * .
}

In JSON format:

{
  delete: [
    // SPO
    {
      "uid": "0x1",
      "name": "Ben"
    },
    // SP*
    {
      "uid": "0x1",
      "name": null
    },
    // S**
    {
      "uid": "0x1"
    }
  ]
}

Now a kicker with using the S** method, is that this only works to delete all predicates of the associated type (dgraph.type). If your node does not have a type, then the S** method practically does nothing. I am not sure give your berevity of context, if you are using types or not.

And then another thing to know, is that a uid itself is not stored without a predicate or object. So if you query looking to see if the uid exists after you delete everything, it will always exist. Here is some more explanation around this concept:

1 Like

Hey Anthony, thank you so much for the clarification!