How to delete a "row"?

I must be missing something obvious. I have the following schema:

<c.period>: int @index(int) .
<c.amount>: int .

Let’s add some data:

{
  set {
    _:x <c.period> "1" .
    _:x <c.amount> "100" .
  }
}

Dgraph then returns:

{
  "data": {
    "code": "Success",
    "message": "Done",
    "uids": {
      "x": "0x382e4"
    }
  }
}

Let’s delete it:

{
  delete {
    <0x382e4> * * .
  }
}

Let’s check that it’s deleted:

query {
  x(func: uid(0x382e4)) {
    uid
    c.period
    c.amount
  }
}

Dgraph returns:

{
  "data": {
    "x": [
      {
        "uid": "0x382e4",
        "c.period": 1,
        "c.amount": 100,
      }
    ]
  },
}

It’s not deleted! What’s wrong with my delete command?

You need to set the Type System to be able to delete entities.

Two questions:

(1) How do I define a type?

type User {
	u_email
}
<u_email>: string @index(hash) @upsert .

or

type User {
	u_email: string @index(hash) @upsert
}

or…?

The example in https://blog.dgraph.io/post/release-v1.1.0/ and https://docs.dgraph.io/master/query-language/#type-system are conflicting and very minimal.

(2) How do I delete using a type? https://docs.dgraph.io/master/mutations/#delete doesn’t even mention type.

you right, need to fix that.

It depends on what version you are. If you’re using the master version, use the first one. Else, use the last.

UPDATE: I just noticed today that the last example is wrong. @index(hash) @upsert These params don’t exists in the Schema type.

Thanks for your prompt reply. I’ll wait for the documentation to be updated then.

If you’re using the master version, use the first one. Else, use the last.

For future-proofing my app, I should use the first one then?

yes

https://github.com/dgraph-io/dgraph/pull/4017

Hi @MichelDiz, when can I see the updated doc about deletion with type? I’m sorry for keep asking, the language is still unintuitive for me, so I need a lot of hand-holding.

Not sure if I understood. All deletions can only happen if you have your entities with well-defined Types. In the case of Type System. This is already in the documentation and explained in the blog articles on the topic. In case you want something more “current” with the Master branch. You can choose to view the “Master” documentation.

Cheers.

PS.
https://github.com/dgraph-io/dgraph/issues/4263

Hi @MichelDiz , sorry for not being clear. In summary:

  1. I asked how to delete a row.
  2. You said, “You need to set the Type System to be able to delete entities.”
  3. I asked how to delete entities (assuming I already set the Type System), because there’s no example in documentation.
  4. You said, “need to fix that (documentation)”.
  5. I asked when the documentation will be fixed/updated with example.
  6. You said, “In the case of Type System. This is already in the documentation and explained in the blog articles on the topic.”

But I asking how to delete. Please advise.

Sorry the delay, I’m having trouble with the internet provider.

As you’re already doing.

Need to fix mentions only. The answer is that you need to define the Type to be able to delete. Without it, It happens exactly what you are going through.

it is just mentions

See

This is your type.

type User {
	u_email: String 
  # In master version you don't need to define the types "int, uid, string..."
  # but you need to define it in some latest releases.
  # Next release it will be more simple the type system
}
<u_email>: string @index(hash) @upsert .

Your data need to be like this

{
  set {
    _:x <u_email> "some@guy.com" .
   # You need to set the type of your entities in your mutation
    _:x <dgraph.type> "User" . 
    _:x <name> "Some Guy" .
  }
}

Now you can delete

{
  delete {
    <0x382e4> * * .
  }
}

Cheers.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.