@upset directive doesn't ensure uniqueness

bug
mutation

(Cbwleft) #1

for example:

<id>: string @index(exact) @upsert .

upsert {
  query {
    v as var(func: eq(id, "1"))
  }

  mutation {
    set {
      uid(v) <id> "1" .
      uid(v) <name> "first node" .
    }
  }
}

upsert {
  query {
    v as var(func: eq(id, "2"))
  }

  mutation {
    set {
      uid(v) <id> "2" .
      uid(v) <name> "second node" .
    }
  }
}

upsert {
  query {
    v as var(func: eq(id, "2"))
  }

  mutation {
    set {
      uid(v) <id> "1" .
      uid(v) <name> "second node" .
    }
  }
}

then I got two nodes with same id, one name “first node”, another name “second node”.


(Michel Conrado) #2

use “Conditional Upsert” for this case https://docs.dgraph.io/mutations/#conditional-upsert


(Akrillis) #3

Could you please give an example of Conditional Upsert with golang dgo2 library syntax? I’ve tried several times but still get syntax errors about “if” or “@if” etc.


(Akrillis) #4

Found: api.Mutation.Cond