Eq function can't use with val()

I have a predicate named “password”, it’s schema is: password string @index(hash) .

now the conditional upsert not work:

upsert{
  query{
    q(func:uid(0xc352)){
      pd as password
    }
  }
  
  mutation @if(eq(val(pd), "123456")) {
    set{
      <0xc352> <password> "222222" .
    }
  }
}

the password of node 0xc352 is realy “123456”…Is that because val(pd) is an array?

Conditional upsert doesn’t support inequality on val. Just length. Change your query to:

upsert{
  query{
    v as var(func:uid(0xc352)) @filter(eq(password, "123456")) {
      password
    }
  }
  
  mutation @if(eq(len(v)) {
    set{
      <0xc352> <password> "222222" .
    }
  }
}

BTW, you should use password-type https://dgraph.io/docs/query-language/schema/#password-type

1 Like

Great,thank you!