Problem while using uid in if condition in a conditional upsert operation

    var (func: eq(, "Matt")){
       id as uid
  mutation @if(eq(val(id), 0x001)){
      uid(id) <user.job> "Engineer"

In this case, the if condition does not return true which will in turn execute the set operation. I know for the fact that user Matt’s uid is 0x001 and even when the var block is used separately as a query block to display Matt’s uid, it displays 0x001 but, the if condition does not return true.

EDIT : changed the previous if condition from @if(val(id), 0x001) to @if(eq(val(id), 0x001)) which was the intended query

This isn’t supported. Conditional upserts accepts length functions only, no other feature. Length is the recommended function for this case.


upsert {
  query {
    ID  as var(func: eq(, "Matt"))
    check as var(func: uid(ID)) @filter(uid(0x001))

  mutation @if(eq(len(check), 1) ) {
    set {
      uid(check) <user.job> "Engineer"

But, this only ensures the existence of the uid but it wouldn’t make sure if check is equal to a uid that you might want to give as an operand to eq function. Am I right?

The filter @filter(uid(0x001)) guarantees to you that. So, if “Matt” uid isn’t equal to 0x001 it will fail and it will return a length of 0. If it is equal to 0x001 it will succeed and return a length of 1 and execute the mutation in the upsert block.

Actually, you don’t need the “check” block, you can do that in the first block. I did it this way to be visually didactic.

Sounds like a good workaround.

BTW see this issue - Really curious that the interest on this has increased in the last 24 hours.

That sounds great, now we can put conditional upsert to extensive with the addition of other functions inside if.