Can't delete a node with upsert

I have a node, it has two attr, one is “name” and one is “description”, when I try to delete an attr, it works:

upsert {
  query {
    q(func: eq(name, "结核杆菌")) {
      d as uid
    }
  }

  mutation {
    delete {
      uid(d) <description>  * .
    }
  }
}

I query the node with

{
 q2(func: has(name)) {
   name
   description
 }
}

then I found out that the description attr had been deleted.

But when I try to delete the node, it fail:

upsert {
  query {
    q(func: eq(name, "结核杆菌")) {
      d as uid
    }
  }

  mutation {
    delete {
      uid(d) *  * .
    }
  }
}

By the way, I try the upsert in ratel UI in “Mutate” block.
After I run the upsert to delete the node, I can still query the node “结核杆菌” in “Query” block with :

{
 q2(func: has(name)) {
   name
   description
 }
}

To be able to delete something. You need a well-defined Type Schema and also your nodes need a predicate "dgraph.type": "User".

See
https://dgraph.io/docs/howto/migrate-dgraph-1-1/#type-system
https://dgraph.io/docs/query-language/type-system/

I did added the node with a type: _:p <dgraph.type> "Project" .
But I still can’t delete it.


I make a mistake, I add the type with other node, not this node. I can delete the node with a type now.

I would almost put money on it that you are missing the commitNow attribute. that is a new concept to most people coming into Dgraph. Doing a mutation without it makes it look like it is doing the delete, but it is really just preparing a delete and not committing the changes until it is told to.

I use ratel UI in “Mutate” block, I just click the “Run” button. And I see the chrome DevTools with the “Network” tab, I see the mutation did have “commitNow=true” attribute.

1 Like

By the way, the response is:

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": [
        {
          "uid": "0x9c43"
        }
      ]
    },
    "uids": {}
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 12646,
      "processing_ns": 34508678,
      "encoding_ns": 17133,
      "assign_timestamp_ns": 428715,
      "total_ns": 35096636
    },
    "txn": {
      "start_ts": 101350,
      "commit_ts": 101351,
      "preds": [
        "1-dgraph.type"
      ]
    }
  }
}

Oh, sorry, my fault, @ MichelDiz is right, I forgot the type…
I add the type with other node, not this node, I can delete the node with a type now.Thanks all of you to reply. :grinning:

2 Likes