I’ve copied and tweaked the portion of the dgo examples_test.go file that relates to using a DeleteJson mutation.
It seems to only delete the dgraph.type of the deleted instance and not the other fields (e.g. uid, name, age).
I have …
type Person struct {
Uid string `json:"uid,omitempty"`
Name string `json:"name,omitempty"`
Age int `json:"age,omitempty"`
DType []string `json:"dgraph.type"`
}
ap := Person{
Name: "Alice",
Age: 21,
DType: []string{"Person"},
}
and
d := map[string]string{"uid": <the actual uid>}
pb, err = json.Marshal(d)
if err != nil {
log.Fatal(err)
}
mu = &api.Mutation{
CommitNow: true,
DeleteJson: pb,
}
_, err = dg.NewTxn().Mutate(ctx, mu)
if err != nil {
log.Fatal(err)
}
When I query for eq(dgraph.type, "Person"), the instance is not found, but when I query for func: uid("<the actual uid>"), the instance is found, including name and age.
Well, we have a problem here. Even though your ap object is of struct Person, the pb object is just a []byte representation of the d map. The passed pb does not contain the dgraph.type value ( which it must definitely contain when calling deletion mutation for deleting the entire node). Use the DeleteNquads attribute instead if you just want to delete the entire node given only the uid