Delete data from graph

This should be fairly straight forward but I can’t find any reference to delete semantics. If you want to delete data from your graph do you want to delete just the edge or can you delete a node and have it clean up all the edges attached to it? What do the queries look like to do something like this?

Hi @jseely,

You’d generally delete the edges. The node / entity doesn’t get deleted. Typically del operation would be part of our mutation segment, but support for it isn’t present in v0.3 yet.

mutation { set {<alice> <follows> <bob> . \n <alice> <name> "Alice" . \n <bob> <name> "Bob" . }}
mutation { del { <alice> <follows> <bob> . }}

We can set it for v0.4 release, if you think this would be useful.

Thanks Manish,
I’m just playing around with it right now. That does seem like something that would be useful at some point though.

1 Like

Hi @mrjn,
thanks for your answer. I think you answer assumes that the user knows in advance the uid of the predicate. Is there a way to enumerate all the nodes in the graph and only after delete every relationship for every node?


Hi @AlBar,

Are you looking to delete everything? Or all the data for nodes matching some query?

For the first, the way to remove the whole database is to stop dgraph, remove the p and w directories and then restart.

For the second, it’s on the way (until it’s part of the query, the process is: query first, then issue a delete mutation)


Thanks @michaelcompton,
problem solved.


I’m using docker compose to start dgraph, I did rm p w zw in ~/dgraph directory, and restart container, nothing happens, data still the same

If you removed it, and verified it was removed. It does not make sense to continue everything as before.

I do not know how you are doing things, whether you are entering the container, whether you are using exec, if you are deleting this folder locally. If you can give more details. I’ll help you. So, I’ll assume you did not use Docker’s exec. So there you go.

Run the compose, open another terminal and do the following.
Assuming that 765511b2869e is the right container.

docker exec 765511b2869e sh -c 'rm -rf /dgraph/* '

Stop the Docker compose, and start again.

This should work, but if it does not work out. You can try a “silly hack”. Change the volume name to “DgraphV2” or something like that in your docker-compose.yml.

But this will create a new volume in your Docker. It is recommended that you use the Docker Prune commands to clean up unused volumes.

      - type: volume
        source: dgraphV2 # <== here
        target: /dgraph
  dgraphV2: # <== here

But you can search for the volume used and delete it directly. Instead of renaming the volume.