# Cannot delete node by json

**URL:** <https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121>\
**Category:** Dgraph Clients\
**Tags:** kind:question, dgo\
**Created:** [June 28, 2020, 11:44am UTC](https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121 "2020-06-28T11:44:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [June 28, 2020, 11:44am UTC](https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121/1 "2020-06-28T11:44:00Z")

</div>

**Moved from GitHub [dgo/129](https://github.com/dgraph-io/dgo/issues/129)**

_Posted by_ [linuxr](https://github.com/linuxr):

Hi, I could not delete node by uid, could someone help me.

My code is :

```auto
type Person struct {
        Uid string `json:"uid"`
        Name string `json:"name"`
        Age int `json:"age"`
        Friends []Person `json:"friends"`
}

func main() {
        c := NewDgraphClient()
        err := CreateSchema(c)
        if err != nil {
                log.Fatal(err)
        }
        err = AddSomeData(c)
        if err != nil {
                log.Fatal(err)
        }
        err = DeleteData(c)
        if err != nil {
                log.Fatal(err)
        }

}

func NewDgraphClient() *dgo.Dgraph {
        conn, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
        if err != nil {
                log.Fatal(err)
        }

        client := dgo.NewDgraphClient(api.NewDgraphClient(conn))

        return client
}

func CreateSchema(client *dgo.Dgraph) error {
        schema := `
name: string @index(term) .
age: int .
friends: [uid] .

type Person {
  name: string
  age: int
  friends: [Person]
}
`
        op := &api.Operation{Schema: schema}

        err := client.Alter(context.Background(), op)
        return err
}

func AddSomeData(client *dgo.Dgraph) error {
        p1 := &Person{
                Uid: "_:dog",
                Name: "Dog",
                Age: 10,
        }
        p1.Friends = make([]Person, 0)

        p2 := &Person{
                Uid: "_:monkey",
                Name: "Monkey",
                Age: 20,
        }
        p3 := &Person{
                Uid: "_:cat",
                Name: "Cat",
                Age: 30,
        }

        p1.Friends = append(p1.Friends, *p2)
        p1.Friends = append(p1.Friends, *p3)

        mu := &api.Mutation{CommitNow: true}
        pb, err := json.Marshal(p1)
        if err != nil {
                return err
        }

        mu.SetJson = pb
        _, err = client.NewTxn().Mutate(context.Background(), mu)
        return err
}

func DeleteData(client *dgo.Dgraph) error {
        d := map[string]string{"uid": "0xfffd8d67d832b97d"}
        pb, err := json.Marshal(d)
        if err != nil {
                return err
        }
        fmt.Println(string(pb))
        mu := &api.Mutation{
                CommitNow: true,
                DeleteJson: pb,
        }

        _, err = client.NewTxn().Mutate(context.Background(), mu)
        return err
}

```

**DeleteData** had not delete any data.  
0xfffd8d67d832b97d is uid of the data created by \*_AddSomeData_.  
I find this uid by [http://localhost:8000](http://localhost:8000)

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 6, 2020, 9:44am UTC](https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121/2 "2020-07-06T09:44:06Z")

</div>

[AugustDev](https://github.com/AugustDev) _commented_ :

I haven’t run the code, but your node struct is not properly implemented and is lacking `DType`. You should redefine your struct and insert `DType` to every instance of the struct.

```auto
type Person struct {
        Uid string `json:"uid"`
        DType []string `json:"dgraph.type,omitempty"`
        Name string `json:"name"`
        Age int `json:"age"`
        Friends []Person `json:"friends"`
}

p1 := &Person{
        DType: []string{"Person"},
	Uid: "_:dog",
	Name: "Dog",
	Age: 10,
}

```

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 7, 2020, 12:20pm UTC](https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121/3 "2020-07-07T12:20:50Z")

</div>

[NamanJain8](https://github.com/NamanJain8) _commented_ :

As @AugustDev suggested, @linuxr for deleting a node you need to have a well-defined type system and your node has predicate \<dgraph.type\>. ref: [node-exists-after-deleting](http://discuss.hypermode.com/t/why-does-it-still-exist-after-deleting-the-node-it-has-not-really-been-deleted/7069/4)

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 11, 2020, 3:56am UTC](https://discuss.dgraph.io/t/cannot-delete-node-by-json/8121/4 "2020-07-11T03:56:32Z")

</div>


