DQL JSON Delete All

I am wondering how to delete all nodes of type X in DQL using JSON format:

{
  "delete": {
    "dgraph.type": "Private",
    "uid": "*",
  }
}

I am looking for the equivalent of this:

upsert {
  query {
    d as var(func: eq(dgraph.type, "Private"))
  }
  mutation {
    delete {
      uid(d) * * .
    }
  }
}

Is this possible using JSON?

J

1 Like

Something like this(need to check if the “Private” quotes need escaping)

S * *

curl -H "Content-Type: application/json" -X POST localhost:8080/mutate?commitNow=true -d '{
  "query": "{ d as var(func: eq(dgraph.type, "Private")) }",
  "delete": {
    "uid": "uid(d)"
  }
}' | jq

S P *

curl -H "Content-Type: application/json" -X POST localhost:8080/mutate?commitNow=true -d '{
  "query": "{ d as var(func: eq(dgraph.type, "Private")) }",
  "delete": {
    "uid": "uid(d)",
    "myPredicate": "null",
  }
}' | jq

2 Likes

I tried this:

{
  "query": "{ d as var(func: eq(dgraph.type, \"Private\")) }",
  "delete": {
    "uid": "uid(d)"
  }
}

It says Message: Done in ratel, but nothing was deleted.

J

Make sure your schema is right.

More details https://dgraph.io/docs/mutations/json-mutation-format/#deleting-edges

My schema was made in GraphQL.

type Private {
  text: String
  …
}

I’m trying to do S * *

J

Do you need the upsert keyword??

It doesn’t look like they do in the example:

https://dgraph.io/docs/mutations/upsert-block/

But maybe the example was wrong?

I am thinking S * * is not possible but S P * is.

J

Nm, got it to work. I took off the quotes in Private, and there was something wrong with ratel.

{
  "query": "{ d as var(func: eq(dgraph.type, Private)) }",
  "delete": {
    "uid": "uid(d)"
  }
}

J