Performing a S * * delete using the Go client

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?

I guess is this what you looking for

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?

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: Get started with Dgraph

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?

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.