1

api.NQuad是否可以使用from从给定节点中删除与谓词匹配的所有边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.Staras ObjectId 但这些解决方案都不起作用

4

1 回答 1

1

这很违反直觉,但要删除边,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)
}
于 2018-08-09T13:05:50.597 回答