2

https://dgraph.io/tour/schema/8/

shows some options for deleting

  1. Delete a single triple
  2. Delete all triples for a given edge
  3. Delete all triples for a given node

Now i'd like to delete all triple for nodes of a given type. I assume this is done by some kind of combination of a query that selects the nodes for the the given type and then a mutation for each of these nodes. I couldn't find an example for this in the tutorial.

Let's assume I'd like to delete all triples for nodes of the type Country.

I know how to select the uids for the nodes:

    {  
      query(func: has(<dgraph.type>)) @filter(eq(<dgraph.type>, "Country")) {
        uid
      }
    }

But how do i combine this with a mutation?

https://discuss.dgraph.io/t/how-to-bulk-delete-nodes-or-cascade-delete-nodes/7308

seems to ask for an "upsert"

How could the deletion of all triples for nodes with a given type be achieved?

1 Answer 1

4

the following upsert seems to work:

upsert {  
  query {
    # get the uids of all Country nodes
     countries as var (func: has(<dgraph.type>)) @filter(eq(<dgraph.type>, "Country")) {
        uid
    }
  }
  mutation {
    delete {
      uid(countries) * * .
    }
  }
}
3
  • That doesn't scales well. Has func is a too wide func. You should use eq instead. If you use has, it will do a lookup for all types on your system and then apply the filter. If you use the eq already in the root, Dgraph would look right away in the index table and execute the operation. Commented Aug 26, 2020 at 2:47
  • @MichelConradoDiz thx for the hint. what would the query look like then? Commented Aug 26, 2020 at 5:55
  • 1
    Just like countries as var(func: eq(<dgraph.type>, "Country") ) or countries as var(func: type("Country") ) Commented Aug 27, 2020 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.