Update without insert

Hi,

Is there a way to update an existing node without inserting a new one if the node doesn’t exist?
If I use regular mutation with set and the triple <0x123ef> <User.name> "Spinelsun", then if 0x123ef doesn’t exist it will be created. The same is true for upsert.
I want to get an error if I try to update a node that doesn’t exist.
Also, the same request applies for deleting a node.

Thanks,
Spinelsun

Yup. https://dgraph.io/docs/mutations/conditional-upsert/#example-of-conditional-upsert

like:

upsert {
  query {
    U as var1(func: uid(0x9c49)) @filter(has(dgraph.type)) { # or @cascade. Why? Look post below.
      uid
      dgraph.type
      expand(_all_)
    }
  }
  mutation @if(eq(len(U), 1)) {
    set {
       uid(U) <elementName> "Test" .
    }
  }
}

You can get resp things and check if operation was done or not.

@ppp225 Great Thanks!

For some reason it doesn’t work in Ratel mutate window, do you know why?

N̶o̶ ̶i̶d̶e̶a̶.̶ ̶W̶o̶r̶k̶s̶ ̶f̶o̶r̶ ̶m̶e̶.̶ ̶D̶o̶ ̶y̶o̶u̶ ̶s̶e̶e̶ ̶a̶n̶y̶ ̶e̶r̶r̶o̶r̶s̶?̶ ̶N̶o̶ ̶e̶r̶r̶o̶r̶s̶ ̶u̶s̶u̶a̶l̶l̶y̶ ̶m̶e̶a̶n̶ ̶s̶o̶m̶e̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶s̶ ̶h̶a̶v̶e̶ ̶w̶r̶o̶n̶g̶ v̶a̶l̶u̶e̶s̶.̶ ̶ ̶M̶a̶k̶e̶ ̶s̶u̶r̶e̶ ̶a̶l̶l̶ ̶y̶o̶u̶r̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶s̶ ̶a̶r̶e̶ ̶c̶o̶r̶r̶e̶c̶t̶,̶ ̶l̶i̶k̶e̶ ̶t̶h̶e̶ ̶u̶i̶d̶ ̶o̶n̶e̶s̶.̶ ̶A̶l̶s̶o̶ ̶m̶a̶k̶e̶ ̶s̶u̶r̶e̶ ̶y̶o̶u̶ ̶u̶s̶e̶ ̶n̶e̶w̶e̶s̶t̶ ̶d̶g̶r̶a̶p̶h̶ ̶v̶e̶r̶s̶i̶o̶n̶.̶

ayy… Sorry. Just noticed my mistake. Problem with filtering on uid is that uid always exist. It should be filtered not on uid but a different predicate. So in query when querying eq(myID, "123") will work fine. Or if we need uid, then add additional filter or directive to validate the node exists. @cascade or @filter(has(dgraph.type)) should be enough. I fixed and edited the query above.