是否可以使用 api.NQuad
从给定节点中删除与谓词匹配的所有边?来自 github.com/dgraph-io/dgo/protos/api
?
我正在努力实现相当于 delete {0x1234 <test.likes> * }
的效果
func TestDeleteQuad(t *testing.T) {
subject := "0x01"
ctx := context.TODO()
d, err := grpc.Dial(testEndpoint, grpc.WithInsecure())
if err != nil {
panic(err)
}
client := dgo.NewDgraphClient(api.NewDgraphClient(d))
txn := client.NewTxn()
defer txn.Discard(ctx)
if _, err := txn.Mutate(ctx, &api.Mutation{Del: []*api.NQuad{
&api.NQuad{
Subject: subject,
Predicate: "test.likes",
ObjectId: "*",
ObjectValue: nil,
},
}}); nil != err {
panic(err)
}
err = txn.Commit(ctx)
assert.NoError(t, err)
}
我尝试使用 "*"
""
x.Star
作为 ObjectId,但这些解决方案均无效
最佳答案
这很违反直觉,但是要删除边,必须使用 ObjectValue
而不是 ObjectId
必须设置为 api.Value_DefaultVal
星级:
func TestDeleteQuad(t *testing.T) {
subject := "0x01"
ctx := context.TODO()
d, err := grpc.Dial(testEndpoint, grpc.WithInsecure())
if err != nil {
panic(err)
}
client := dgo.NewDgraphClient(api.NewDgraphClient(d))
txn := client.NewTxn()
defer txn.Discard(ctx)
if _, err := txn.Mutate(ctx, &api.Mutation{Del: []*api.NQuad{
&api.NQuad{
Subject: subject,
Predicate: "test.likes",
ObjectValue: &api.Value{&api.Value_DefaultVal{x.Star}}, // <- this
},
}}); nil != err {
panic(err)
}
err = txn.Commit(ctx)
assert.NoError(t, err)
}
关于go - 如何使用 dgo api.NQuad 删除 dgraph 中的四边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763284/