JCzz
(J Czz)
1
How do you delete a node in a func?
For starters I have the following:
curl localhost:8080/alter -XPOST -d $'
{
deleteusername(func: eq(user.name, "Alice")) {
uid
delete {
uid # and maybe * * .
}
}
}
' | python -m json.tool | less
I get:
{
"errors": [
{
"code": "Error",
"message": "Unexpected token: lex.Item [6] \"{\" while parsing schema"
}
]
}
jespersm
(Jesper Steen Møller)
2
You’ve got a typo in the URL for starters: /alter is used for schema changes, /mutate is for mutations.
JCzz
(J Czz)
3
Yes, thanks Jesper
So now I am at this error:
{
“errors”: [
{
“code”: “ErrorInvalidRequest”,
“message”: “Invalid mutation formatting.”
}
]
}
MichelDiz
(Michel Diz)
4
JCzz
(J Czz)
5
Thanks Michel
I did play around with this, do you know how I can delete without knowing the uid upfront?
MichelDiz
(Michel Diz)
6
Dgraph query and mutation are distinct operations that do not mix.
You must first query, collect the UIDs and then do the deletion process.
JCzz
(J Czz)
7
Sorry, but there must be is something I totally dont get.
From:
https://docs.dgraph.io/mutations/#mutations-using-curl
Running from terminal, this does not work:
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:
curl -X POST localhost:8080/mutate -d $'
{
delete {
_:alice <name> "Alice" .
}
}'
Or Ratel:
{
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:
curl -X POST localhost:8080/mutate -d $'
{
delete {
_:alice <name> "Alice" .
}
}'
Hope you can help, thanks in advance
jespersm
(Jesper Steen Møller)
8
Shouldn’t you also set the commit headers?
curl -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true'
…
JCzz
(J Czz)
9
Good thinking, but as I understand it - the json part is:
curl -X POST localhost:8080/mutate -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true' -d $'
{
"delete": [
{
"uid": "0xa"
}
]
}' | jq
Where as:
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
MichelDiz
(Michel Diz)
10
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
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
Also, please do our Tour https://tour.dgraph.io/
JCzz
(J Czz)
11
I did go through all https://tour.dgraph.io/
Very good tour!
I just think the documentation is misleading by giving the samples, that is all - thanks.
curl -X POST localhost:8080/mutate -d $'
{
delete {
_:alice <name> "Alice" .
}
}'
MichelDiz
(Michel Diz)
12
oh yeah! I see now. It’s my fault. I didn’t noticed it.
I’ll fix that, thanks!
2 Likes
system
(system)
Closed
13
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.