Dgo DeleteJson Mutation removes the dgraph.type but not the other fields

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

1 Like

The only way I see to make it works is by doing the following. Is that right?

	pb = []byte(fmt.Sprintf(`
<%s> <dgraph.type> * .
<%s> <name> * .
<%s> <age> * .
`, alice, alice, alice))
	fmt.Printf("\nFor deleting   %s\n", pb)

	mu = &api.Mutation{
		CommitNow:  true,
		DelNquads: pb,
	}

	_, err = dg.NewTxn().Mutate(ctx, mu)

If you want to remove the entire thing just write the following →

pb = []byte(fmt.Sprintf(`<%s> * * .`, alice))

This in essence means delete the uid for any given predicate and any assigned value

When I do it that way, the fields don’t get deleted. They’re still available with the original data.

Even if I do

 	pb = []byte(fmt.Sprintf(`
 <%s> <dgraph.type> * .
 <%s> * * .`, alice, alice))

it doesn’t delete the data