Hi,
I’m using the Go client and am having an issue when trying to add a new node with a relationship to an existing node.
Here’s an example of a schema and structs:
network: string .
address: string .
ip.network: uid @reverse .
type network struct {
UID string `json:"uid,omitempty"`
Network string `json:"network,omitempty"`
}
type ip struct {
UID string `json:"uid,omitempty"`
Address string `json:"address,omitempty"`
NetworkUID string `json:"ip.network,omitempty"`
}
I first create the network
and store the result in a variable called nw
.
I then want to create an IP address and add the relationship to the network by passing the network UID to the NetworkUID
field of the ip struct.
So my, simplified, code then looks like this:
addr := ip{
Address: "192.168.1.1",
NetworkUID: nw.UID,
}
mu := &api.Mutation{
CommitNow: true,
}
a, err := json.Marshal(addr)
if err != nil {
fmt.Println(err)
}
mu.SetJson = a
_, err = dg.NewTxn().Mutate(context.Background(), mu)
if err != nil {
fmt.Println(err)
}
And then I get the following error when attempting to run the mutation:
Transaction has been aborted. Please retry.
The JSON looks like this:
{
"address":"192.168.1.1",
"ip.network":"0xc451"
}
All works fine without trying to pass the relationship. I can add the relationship manually with no problems in Ratel, I’m just not sure how to do it via the Go client.
I must be doing something simple wrong…but I can’t work out what right now. Can anyone help?
Thanks