Vivat
(Vitaliy Vostrikov)
December 15, 2017, 10:31am
1
I create entity:
import (
dataBaseAPI "github.com/dgraph-io/dgraph/protos/api"
dataBaseClient "github.com/dgraph-io/dgraph/client"
)
transaction := client.NewTxn() // *dataBaseClient.Dgraph
encodedCategory, err := json.Marshal(category)
if err != nil {
log.Println(err)
return category, ErrCategoryCantBeCreated
}
mutation := &dataBaseAPI.Mutation{
SetJson: encodedCategory,
CommitNow: true,
}
assigned, err := transaction.Mutate(context.Background(), mutation)
category.ID = assigned.Uids["blank-0"]
How I can now delete that entity?
I try this:
transaction := client.NewTxn() // *dataBaseClient.Dgraph
encodedCategory, err := json.Marshal(category)
mutation := dataBaseAPI.Mutation{
DeleteJson: encodedCategory,
CommitNow: true,
}
assigned, err := transaction.Mutate(context.Background(), &mutation)
and I get error:
“Transaction has been aborted. Please retry.”
In previous version i use:
request := dataBaseClient.Req{}
err = request.DeleteObject(&category)
_, err = client.Run(context.Background(), &request)
pawan
(Pawan Rawal)
December 15, 2017, 10:39am
2
Hey @Vivat
We have an example for deleting a node here . Essentially, you just marshal the uid of the node to be deleted and send it using DeleteJson
.
This message indicates that the related node or indexes were modified by some other transaction. This is a temporary error and we recommend that you retry the transaction when you get this error. You could also set IgnoreIndexConflict
to be true while adding mutations which would reduce the probability of aborts.
Vivat
(Vitaliy Vostrikov)
December 15, 2017, 6:03pm
3
Thanks, I tried marshal only uid and it work now.
Right:
type Category struct {
ID string json:"uid,omitempty"
}
DeleteCategory(category Category) (string, error) {
encodedCategory, err := json.Marshal(Category{ID: category.ID})
…
Not right:
DeleteCategory(category Category) (string, error) {
encodedCategory, err := json.Marshal(category)
…
system
(system)
Closed
January 14, 2018, 6:03pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.