How to bulk delete nodes or cascade delete nodes?

This is my schema:

type Group {
    name
    members
    posts
}
name: string @index(hash) .
members: [uid] @reverse @count .
posts: [uid] @reverse @count .

Each group has many members and posts, the number is very large, and may even exceed one million. When I delete this group, I must delete all the members and posts of this group. What should I do?

Does dgraph support batch cascade delete ?

You should use Upsert Block for this

upsert {
  query {
    V as var(func: type(Group)) @filter(eq(name, "MyGroup")){
      M as members
      P as posts
    }
  }

  mutation {
    delete {
      uid(V) * * .
      uid(M) * * .
      uid(P) * * .
    }
  }
}

Can be also like this using recurse (Which is similar to the concept behind the word ā€œcascadeā€ that you used):

upsert {
  query {
    V as var(func: type(Group)) @filter(eq(name, "MyGroup")) @recurse(depth: 5) {
      REST uid
      name
      subgroup
    }
  }

  mutation {
    delete {
      uid(V) * * .
      uid(REST) * * .
    }
  }
}

Cheers.

3 Likes

Great, thanks for your help. :clap:
Cheers.