Delete operation in Dgraph using GRPC

Reading Time: 2 minutes

Deletion in dgraph is an easy operation we just have to keep few things in mind before deleting anything in dgraph.
Before I explain how can we delete I am going to explain the different scenario.

For example,

  1. Delete the edge
  2. Delete the node.
  3. Delete the one value in a list

We will take a scenario where we have a person who has the following attribute

  • uid – string
  • personType – string
  • name – string
  • age – int
  • hobbies – list of string
  • address – User-defined Class Address(houseNumber, street, city, state, addressType, uid)

Where the address is an edge from Person node to address node. Now that we are aware of the structure of the dgraph so no more waiting we will go ahead and do some deletion.

Deleting the edge

We have to delete the address edge. To delete it we will need the uid of the person whose address we have to delete and the uid of the address node.

So the POJO structure should be similar to it.

{ “uid”: “0x123”, “address”: { “uid”: “0x456” } }

So POJO structure that we have made.

Calling the method to finally delete the edge.

Delete method which creates the transaction to do the mutation.

This process only deletes the edge between person and address. But if we want completely remove the address node then we have to delete the address node as well.

Now see how to delete the Node.

Delete the Node

We just have to provide the uid of the address node. The deleteNode method is the same as mentioned above.

Delete the value in the List

To delete the value of the list then we have to make the POJO similar to

{ “uid”: “0xd”, #UID of person. “hobbies”: “Apple” }

we will call the method to delete the particular value of the list. we just need the person uid and the value that we need to delete in the list. In the list of hobbies, I want to delete the Drawing hobby.

Conclusion

We have learned the deletion of node, edge, and value in the list using the GRPC client. So if you need more understanding about GRPC client you can refer to the How to use Dgraph in your java application!! blog. For the complete code reference, you can visit GitHub repo.

Reference

Dgraph Offical Site 

Knoldus-Scala-Spark-Services

Written by 

Priyanka Thakur is a Software Consultant having 6 months of experience currently working at Knoldus Software LLP. She has done MCA at BVICAM, GGSIPU. She has a graduation degree in BCA from JIMS, GGSIPU. She is familiar with programming language' s such as C, Java, and Scala. She also has interest in Angular and Docker and currently working on Logam. She is dedicated, focused and hardworking person. Her interests are in to face new programming challenges because she believes these challenges produce opportunity. She is keen to learn new technologies. In her leisure time, she prefers reading about mythology, watching movies.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!