# Selective drop data for a certain type

**URL:** <https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914>\
**Category:** Dgraph Cloud / Slash GraphQL\
**Tags:** status:accepted, kind:feature, ticket:created\
**Created:** [July 22, 2020, 12:09am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914 "2020-07-22T00:09:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 22, 2020, 12:09am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/1 "2020-07-22T00:09:57Z")

</div>

I have a bunch of types in my GraphQL schema, and I want to drop the data for one of those types to aid with my testing. There’s currently no way to do that.

Perhaps, this can be part of the visual schema editor.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [July 22, 2020, 2:33am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/2 "2020-07-22T02:33:58Z")

</div>

Sure there is 😉

Say your type is User

```auto
mutation {
  deleteUser(filter: {}) {
    numUids
  }
}

```

Just pass an empty filter and it will delete all. Figured that out today actually.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 22, 2020, 3:30am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/3 "2020-07-22T03:30:55Z")

</div>

Haha… that’s a nice trick too. It could run into problems at scale, but for smaller datasets it should be alright.

@michaelcompton do you limit the number of results on `deleteType` with empty filter?

Still, I think it should be part of the UI. I doubt most people would realize it on their own.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [July 22, 2020, 3:40am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/4 "2020-07-22T03:40:38Z")

</div>

It could end up very bad too. Say a user who has access to delete data accidentally forgets to finish that filter before submitting the mutation. I would like this to be closed and error out and an actual drop all mutation somehow specifically

---

<div class="post-metadata">

**Author:** ![michaelcompton](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/michaelcompton/32/1774_2.png) [@michaelcompton](https://discuss.dgraph.io/u/michaelcompton)\
**Post date:** [July 22, 2020, 5:36am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/5 "2020-07-22T05:36:20Z")

</div>

I think there’s two separate things here: one is adding a bit more functionality around schema updates (as mentioned in other posts), dropping data, removing a type, etc, and the other is a nice UI for that in Slash.

I think we’ll add some drop data options to `/admin` soon. I’d also like to have some other schema and data management bits in there. For example, there’s a difference between what my app users can do, and what I can do as the developer/admin, so I’d like some data management available through `/admin`. Maybe that could be a place where you could manage a type and all it’s data as a whole. I started an RFC around schema updates before I went on holidays. It’s worth finishing that off and maybe broadening the scope to include some other parts of data/schema management.

(side note: there’s no restrictions if you state deleting everything - that ends up as just a query on the type and delete what you find.)

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 24, 2020, 12:51am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/6 "2020-07-24T00:51:31Z")

</div>

One more thing that’s now coming up. I created a `Stream: [String]`, then realized that I actually just need a string, no need for a list. So, I tried to change it to `String`, and I’m getting this error.

> resolving updateGQLSchema failed because succeeded in saving GraphQL schema but failed to alter Dgraph schema - this indicates a bug in Dgraph schema generation. Please let us know : [Issues · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/issues). Don’t forget to post your old and new schemas in the issue description.: Type can’t be changed from list to scalar for attr: [Tweets.stream] without dropping it first.

Now it has become even more important to allow dropping a field altogether.

Btw, can we remove all the URLs in error messages – it’s a bad idea. @pawan @vvbalaji

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [July 24, 2020, 1:00am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/7 "2020-07-24T01:00:15Z")

</div>

Yep, just like this:

> [@Schema change not allowed from scalar to uid or vice versa while there is data for pred](http://discuss.hypermode.com/t/schema-change-not-allowed-from-scalar-to-uid-or-vice-versa-while-there-is-data-for-pred/8898):
>
> Dgraph Version: v2.0.0-rc1-514-ga69b22f53 Original Schema: type Message { id: ID! to: String! from: String! message: String! } New Schema: type Message { id: ID! to: Contact! from: Contact! message: String! } type Contact { id: ID! name: String! } Error Message: Schema change not allowed from scalar to uid or vice versa while there is data for pred: Message.to Found my existing data and deleted it with the mutation: mutation { deleteMessage(filter: {id: ["0x2","0x…

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [July 24, 2020, 6:41am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/8 "2020-07-24T06:41:13Z")

</div>

> [@mrjn](#):
>
> Btw, can we remove all the URLs in error messages – it’s a bad idea. @pawan @vvbalaji

Yes, there is [a PR](https://github.com/dgraph-io/dgraph/pull/6036) for this which would be merged to master today after CI passes.

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [July 28, 2020, 6:28am UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/9 "2020-07-28T06:28:25Z")

</div>

I’ve added this to a backlog. I’d assume you would like to drop

1. A type
2. An unused field in the type

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [August 21, 2020, 4:35pm UTC](https://discuss.dgraph.io/t/selective-drop-data-for-a-certain-type/8914/10 "2020-08-21T16:35:20Z")

</div>

We had to come up with this because the graphql endpoint kept refusing to delete our data in bulk for a given type.

Here is DQL for dropping a type. For illustration the type here will be `Comments`.

```auto
upsert {
  query {
    comments as var(func: eq(dgraph.type, "Comments"))
  }
  mutation {
    delete {
      uid(comments) * * .
    }
  }
}

```

Make sure you send it to the `/mutate?commitNow=true` endpoint as described in [https://dgraph.io/docs/slash-graphql/advanced-queries/](https://dgraph.io/docs/slash-graphql/advanced-queries/)
