When I insert new data, how do I use one-off execution to verify it first then decide whether to insert a new one or before it is modified

When I insert new data, how do I verify it first, then decide whether to insert a new one or before it is modified.
For example:
I already have a node:
{
_:A "Alic " .
_:A _:Amail .
}

AMnode
{
_:Amail "A@mail.com "
_:Amail “123456”
}

But then, I received the new data (name:A@mail.com , newpass:654321,oldpass:09876) need add to dgraph.

How can i use one-off execution in dgraph get the finally data at the beginning of the node AMnode

{
_:Amail "A@mail.com "
_:Amail “123456”
_:Amail “654321”
_:Amail “09876”
}

Hey @ogreso

You would have the query for the node first using the parameters, if you don’t find anything you create a new node.

{
  me(func:eq(name, "A@mail.com")) @filter(eq(newpass, "654321") AND eq(oldpass, "09876")) {
    uid
  }
} 

Check the result, if the uid exists then use it for updates else create a new node.

Can’t you use just one query statement ?
Like this :
if(func:eq(name, “A@mail.com”)){

updates

}else{

create

}

write the code,And just one time interaction with dgraph

This is not possible right now but something like this might be introduced in upcoming versions. For now, I’d suggest using transactions to achieve this.

Thank you ~ ,I think It’s will be a good function.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.