Performing a S * * delete using the Go client


(Francis Chuang) #1

I want to perform a S * * delete as outlined here: https://docs.dgraph.io/mutations/#delete

I’ve tried using DeleteEdges, but it didn’t seem to work:

mu = &api.Mutation{}
dgo.DeleteEdges(mu, r.Users[0].Uid, "*")

I also tried creating the mutation myself, but it also didn’t seem to work:

mu = &api.Mutation{
	Del: []*api.NQuad{
		{
			Subject:     r.Users[0].Uid,
			Predicate:   "*",
			ObjectValue: &api.Value{Val: &api.Value_DefaultVal{"_STAR_ALL"}},
		},
	},
}

What is the correct way to delete all outgoing edges from a node?


(Michel Conrado) #2

I guess is this what you looking for


(Francis Chuang) #3

Hi Michel, thanks for your response!

The linked example deletes the Alice node and all of its outgoing edges, however, shouldn’t a S * * delete delete all of Alice’s outgoing edges, but leave the Alice node alone?


(Michel Conrado) #4

Hi Francis,
S * * means “clean the whole node”. The node will still exist, but with no values or edges.
If you wanna clean just specific outgoing edges. You have to do: S P *

Note The patterns * P O and * * O are not supported since its expensive to store/find all the incoming edges.

ref: https://docs.dgraph.io/mutations/#delete


(Francis Chuang) #5

Ah, I see. Thanks for the clarification. I think this bit in the docs should be clarified:

The pattern S * * deletes all edges out of a node (the node itself may remain as the target of edges), any reverse edges corresponding to the removed edges and any indexing for the removed data.

From the wording, it sounds like the node itself and its own predicates are kept, but the edges are deleted.

If I need to do a S P * delete, what’s the best way?


(Daniel Mai) #6

Predicates are synonymous with edges. I feel like the docs are clear here, saying that all edges out of a node are deleted.

You can use dgo.DeleteEdges and then call txn#Mutate. As metioned in the godoc, DeleteEdges itself does not apply the mutation.