# How to delete node in a func

**URL:** <https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961>\
**Category:** Users\
**Created:** [January 30, 2019, 3:49pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961 "2019-01-30T15:49:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [January 30, 2019, 3:49pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/1 "2019-01-30T15:49:32Z")

</div>

How do you delete a node in a func?

For starters I have the following:

```auto
curl localhost:8080/alter -XPOST -d $'
	{
		deleteusername(func: eq(user.name, "Alice")) {
      uid
      delete {
        uid # and maybe * * .
      }
		}
	}
' | python -m json.tool | less

```

I get:

```auto
{
    "errors": [
        {
            "code": "Error",
            "message": "Unexpected token: lex.Item [6] \"{\" while parsing schema"
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![jespersm](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jespersm/32/1465_2.png) [@jespersm](https://discuss.dgraph.io/u/jespersm)\
**Post date:** [January 30, 2019, 3:54pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/2 "2019-01-30T15:54:26Z")

</div>

You’ve got a typo in the URL for starters: /alter is used for schema changes, /mutate is for mutations.

---

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [January 30, 2019, 3:59pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/3 "2019-01-30T15:59:20Z")

</div>

Yes, thanks Jesper

So now I am at this error:

{  
“errors”: [  
{  
“code”: “ErrorInvalidRequest”,  
“message”: “Invalid mutation formatting.”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [January 30, 2019, 4:00pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/4 "2019-01-30T16:00:44Z")

</div>

In addition to what Jesper said. You do not perform deletions with Query.  
You need to use RDF or JSON. Follow links.

### RDF

[https://docs.dgraph.io/mutations/#mutations-using-curl](https://docs.dgraph.io/mutations/#mutations-using-curl)  
[https://docs.dgraph.io/mutations/#delete](https://docs.dgraph.io/mutations/#delete)

### JSON

[https://docs.dgraph.io/mutations/#deleting-edges](https://docs.dgraph.io/mutations/#deleting-edges)  
[https://docs.dgraph.io/mutations/#json-syntax-using-raw-http-or-ratel-ui](https://docs.dgraph.io/mutations/#json-syntax-using-raw-http-or-ratel-ui)

---

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [January 30, 2019, 4:06pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/5 "2019-01-30T16:06:32Z")

</div>

Thanks Michel

I did play around with this, do you know how I can delete without knowing the uid upfront?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [January 30, 2019, 4:19pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/6 "2019-01-30T16:19:40Z")

</div>

Dgraph query and mutation are distinct operations that do not mix.  
You must first query, collect the UIDs and then do the deletion process.

---

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [February 1, 2019, 12:24pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/7 "2019-02-01T12:24:12Z")

</div>

Sorry, but there must be is something I totally dont get.

From:  
[https://docs.dgraph.io/mutations/#mutations-using-curl](https://docs.dgraph.io/mutations/#mutations-using-curl)

Running from terminal, this does not work:

```auto
curl -X POST localhost:8080/mutate -d $'
{
  set {
    _:alice <name> "Alice" .
  }
}'

```

I tried also using `docker exec dgraph curl ...`

It does work from Ratel UI.

But mostly in connection to the original question, I am unable to delete from terminal:

```auto
curl -X POST localhost:8080/mutate -d $'
{
  delete {
    _:alice <name> "Alice" .
  }
}'

```

Or Ratel:

```auto
{
  delete {
    _:alice <name> "Alice" .
  }
}

```

I get:  
`: uid not found/generated for xid _:alice`

And if you are supposed to query first and then delete, using uid -I dont understand the documentation:

```auto
curl -X POST localhost:8080/mutate -d $'
{
  delete {
    _:alice <name> "Alice" .
  }
}'

```

Hope you can help, thanks in advance

---

<div class="post-metadata">

**Author:** ![jespersm](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jespersm/32/1465_2.png) [@jespersm](https://discuss.dgraph.io/u/jespersm)\
**Post date:** [February 1, 2019, 12:42pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/8 "2019-02-01T12:42:39Z")

</div>

Shouldn’t you also set the commit headers?  
`curl -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true'` …

---

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [February 1, 2019, 12:58pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/9 "2019-02-01T12:58:23Z")

</div>

Good thinking, but as I understand it - the json part is:

```auto
curl -X POST localhost:8080/mutate -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true' -d $'
    {
      "delete": [
        {
          "uid": "0xa"
        }
      ]
    }' | jq

```

Where as:

```auto
curl -X POST localhost:8080/mutate -d $'
{
  delete {
    _:alice <name> "Alice" .
  }
}'

```

is the way dgraph is doing there own json RDF version - but what do I know 🙂

Thanks

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [February 1, 2019, 2:28pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/10 "2019-02-01T14:28:52Z")

</div>

> [@JCzz](#):
>
> ```auto
> curl -X POST localhost:8080/mutate -d $'
> {
> delete {
> _:alice <name> "Alice" .
> }
> }'
> 
> ```

> [@JCzz](#):
>
> : uid not found/generated for xid \_:alice

First point. Mutation / Delation does not query. That is, it will not find “Alice” for you. The `_:alice` is a identifier known as “blank node”.

You need to first find Alice via query and then use like that

```auto
curl -X POST localhost:8080/mutate -d $'
{
  delete {
    <0x56f33> * * . #the "0x56f33" would be Alice's UID
  }
}'

```

The JSON format for deletion you can find in [Get started with Dgraph](https://docs.dgraph.io/mutations/#json-syntax-using-raw-http-or-ratel-ui)

Also, please do our Tour [https://tour.dgraph.io/](https://tour.dgraph.io/)

---

<div class="post-metadata">

**Author:** ![JCzz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jczz/32/1775_2.png) [@JCzz](https://discuss.dgraph.io/u/JCzz)\
**Post date:** [February 1, 2019, 2:46pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/11 "2019-02-01T14:46:30Z")

</div>

I did go through all [https://tour.dgraph.io/](https://tour.dgraph.io/)

Very good tour!

I just think the documentation is misleading by giving the samples, that is all - thanks.

```auto
curl -X POST localhost:8080/mutate -d $'
{
  delete {
    _:alice <name> "Alice" .
  }
}'

```

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [February 1, 2019, 2:50pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/12 "2019-02-01T14:50:10Z")

</div>

oh yeah! I see now. It’s my fault. I didn’t noticed it.  
I’ll fix that, thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [March 3, 2019, 2:50pm UTC](https://discuss.dgraph.io/t/how-to-delete-node-in-a-func/3961/13 "2019-03-03T14:50:10Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
