How to programatically drop dgraph data by schema

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

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:

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

You can read more about upserts here.

1 Like

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?

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

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

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

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

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

1 Like

不,这个不是我想要的。不是通过界面删除,通过调用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.

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.

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

拿这个语句删

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

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:

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

Request type is application/json, request verb is POST

1 Like

4 posts were split to a new topic: Finding schemas that the data fulfils

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