Hi
#golang #go #dgo
I use a function by name unset_action for delete an edge between two nodes.
but when I below code it deletes all of the edges.
by example :
I want delete Follow edge from “mehrdad” to “mhb8898” but too delete the Follow edge from “mehrdad” tor “ali” .
I want delete just Follow edge from “mehrdad” to “mhb8898” (only one edge from Follow list)
my code :
func unset_action(action, user1 ,user2 string ,dg *dgo.Dgraph, ctx context.Context) {
mu := &api.Mutation{
CommitNow: true,
}
var resp struct {
Find []struct{
UID string `json:"uid"`
} `json:"find"`
}
// find user 1
person1, err := dg.NewTxn().Query(context.Background(), fmt.Sprintf("{find(func : allofterms(UrlName , %v)){uid}}", user1))
if err != nil {
log.Fatal(err)
}
// parse response json user 1
err = json.Unmarshal(person1.Json , &resp)
if err != nil {
log.Fatal(err)
}
uid1 := resp.Find[0].UID
// find user 2
person2, err := dg.NewTxn().Query(context.Background(), fmt.Sprintf("{find(func : allofterms(UrlName , %v)){uid}}", user2))
if err != nil {
log.Fatal(err)
}
// parse response json user 2
err = json.Unmarshal(person2.Json , &resp)
if err != nil {
log.Fatal(err)
}
// uid2 := resp.Find[0].UID
// query
// query := fmt.Sprintf("<%v> <%v> <%v> . ",uid1 , action , uid2)
// unset action
dgo.DeleteEdges(mu, uid1, "Follow" )
_, err = dg.NewTxn().Mutate(ctx, mu)
if err != nil {
log.Fatal(err)
}
}
Can you help me?!
thanks .