ogreso
(Ogre)
February 7, 2018, 7:38am
1
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”
}
pawan
(Pawan Rawal)
February 7, 2018, 10:36pm
2
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.
ogreso
(Ogre)
February 8, 2018, 7:57am
4
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
pawan
(Pawan Rawal)
February 8, 2018, 11:45pm
5
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.
ogreso
(Ogre)
February 9, 2018, 2:54am
6
Thank you ~ ,I think It’s will be a good function.
system
(system)
Closed
March 11, 2018, 2:54am
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.