# How to programatically drop dgraph data by schema

**URL:** <https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068>\
**Category:** Dgraph\
**Tags:** kind:question\
**Created:** [September 7, 2020, 9:58am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068 "2020-09-07T09:58:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![heshuguo](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@heshuguo](https://discuss.dgraph.io/u/heshuguo)\
**Post date:** [September 7, 2020, 9:58am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/1 "2020-09-07T09:58:51Z")

</div>

as titled.  
I want to delete dgraph data by schema because we have a few schemas, not delete all of them at a time.

---

<div class="post-metadata">

**Author:** ![ahsan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ahsan/32/3517_2.png) [@ahsan](https://discuss.dgraph.io/u/ahsan)\
**Post date:** [September 7, 2020, 11:02am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/2 "2020-09-07T11:02:54Z")

</div>

I assume that you want to delete a particular predicate. Suppose you have a schema in which you have name and age, and you want to delete the age predicate from all the nodes. You can do this like this:

```auto
upsert {
  query {
    q(func:has(age) {
      v as uid
    }
  }
  mutation {
    delete {
      uid(v) <age> * .
    }
  }
}

```

You can read more about upserts [here](https://dgraph.io/docs/mutations/upsert-block/).

---

<div class="post-metadata">

**Author:** ![heshuguo](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@heshuguo](https://discuss.dgraph.io/u/heshuguo)\
**Post date:** [September 7, 2020, 11:42am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/3 "2020-09-07T11:42:04Z")

</div>

No, I just want to delete the data by schema. For example, I have two schemas, which named a and b. I just want to delete the data named schema a. Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 7, 2020, 11:42am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/4 "2020-09-07T11:42:44Z")

</div>

So you want to delete the schema? or, do you want to delete all data that has schema A?

如果用中文比较容易，那就写你的意思。 我帮你翻译

---

<div class="post-metadata">

**Author:** ![heshuguo](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@heshuguo](https://discuss.dgraph.io/u/heshuguo)\
**Post date:** [September 7, 2020, 11:57am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/5 "2020-09-07T11:57:27Z")

</div>

是的，我想删除schema和它下面的所有数据。

TRANSLATION: Yes. I want to get rid of the schema and the data associated with it.

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 7, 2020, 12:17pm UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/6 "2020-09-07T12:17:00Z")

</div>

The correct terminology to use is “drop”, not “delete”.

To drop data, you can use Ratel. Go to the schema tab, then select the schema predicate you want, then click the red DROP button

 ![Screenshot from 2020-09-07 22-12-18](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/3/3a5de51ec6a858770049ba555efcc303f4e883ce.png)

---

<div class="post-metadata">

**Author:** ![heshuguo](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@heshuguo](https://discuss.dgraph.io/u/heshuguo)\
**Post date:** [September 7, 2020, 11:43pm UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/7 "2020-09-07T23:43:19Z")

</div>

不，这个不是我想要的。不是通过界面删除，通过调用dgraph的API来删除数据，类似于关系数据库的drop database xxx；如果有多个schema，想删除一个特定schema的数据，通过api调用来实现，不是通过界面。

TRANSLATION: No. this is not what I want. Not through the web interface to delete. I want to do it through dgraph’s API to drop data, just like in relational databases where you can just do `drop database xxx`. If there are many schema predicates, and you want to drop a particular schema, you want to use an API, not a web interface.

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 8, 2020, 12:26am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/8 "2020-09-08T00:26:16Z")

</div>

I’ll look into ways to programatically drop data from a schema. I recall being able to do it via a HTTP call to `/admin` endpoint. I may be remembering wrong.

---

<div class="post-metadata">

**Author:** ![BlankRain](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/blankrain/32/1592_2.png) [@BlankRain](https://discuss.dgraph.io/u/BlankRain)\
**Post date:** [September 8, 2020, 12:32am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/9 "2020-09-08T00:32:25Z")

</div>

```auto
upsert {
  query {
    q(func:has(age) {
      v as uid
    }
  }
  mutation {
    delete {
      uid(v) <age> * .
    }
  }
}

```

拿这个语句删

---

<div class="post-metadata">

**Author:** ![heshuguo](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@heshuguo](https://discuss.dgraph.io/u/heshuguo)\
**Post date:** [September 8, 2020, 12:36am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/10 "2020-09-08T00:36:59Z")

</div>

这个也是先通过查询属性然后删除，通过先删除属性或者边来删除schema，我想要的是一次性的删除一个shema，类似于drop database xxx这样的语句，有没有这样的api来实现这个功能。

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 8, 2020, 12:56am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/11 "2020-09-08T00:56:04Z")

</div>

OK I did a bit of reverse engineering because I couldn’t find the docs.

What you want to do is send a request to the `/alter` endpoint, not the `/admin` endpoint.

This is the request you send to the `/alter` endpoint:

```auto
{"drop_attr":"SCHEMA PREDICATE YOU WANT TO DROP"}

```

Request type is `application/json`, request verb is `POST`

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 8, 2020, 1:05am UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/12 "2020-09-08T01:05:18Z")

</div>

4 posts were split to a new topic: [Finding schemas that the data fulfils](https://discuss.dgraph.io/t/finding-schemas-that-the-data-fulfils/10084)

---

<div class="post-metadata">

**Author:** ![zxj405](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/zxj405/32/10548_2.png) [@zxj405](https://discuss.dgraph.io/u/zxj405)\
**Post date:** [June 19, 2023, 12:20pm UTC](https://discuss.dgraph.io/t/how-to-programatically-drop-dgraph-data-by-schema/10068/13 "2023-06-19T12:20:04Z")

</div>

这个语句对于数据量多，会很慢，如果我需要删除某个谓词下面所有的数据，用这种方式特别慢。
