How to delete different nodes with same uid?

My json Data is like below

[
  {
    "dgraph.type": "Dog",
    "uid": "_:a",
    "dogName": "a",
    
    "FRIEND_OF": [
      {
        "dgraph.type": "Cat",
        "uid": "_:a",
        "catName": "a"
      }
     
    ]
   
  }
]

Here , the dogName and catName is same.
How can I delete only cat node?
I tried below mutation , but it is deleting both cat and Dog nodes

{
	"delete":[
			{
"uid":"0x34232bce"
  
			}

		]
}

You have a misconception. These are not two different nodes with the same uid as that is impossible. Uid stands for UNIQUE identifier.

What you have is a single node with 2 types and having both the dogName and catName predicates.

If you want to remove only the dog or cat specific data you will have to perform the delete specifically deleting the specific predicates and values.

IMO it is easier to understand using the RDF syntax because you easily see the difference between S** SP* and SPO methods.

delete {
  <0x34232bce> <dgraph.type> "Cat" .
  <0x34232bce> <catName> * .
}

This leaves the Dog dgraph.type value and leaves all other predicates besides the catName which gets deleted no matter what value it has.

1 Like