dongyou8087 2018-08-09 09:21
浏览 81
已采纳

如何使用dgo api.NQuad删除dgraph中的四边形

Is it possible to remove all edges matching a predicate from a given node using api.NQuad from github.com/dgraph-io/dgo/protos/api?

I'm trying to achieve the equivalent of 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)
}

I tried using "*" "" x.Star as ObjectId but none of those solutions work

  • 写回答

1条回答 默认 最新

  • dre75230 2018-08-09 13:05
    关注

    This is quite counter intuitive, but to delete edges, ObjectValue must be used instead of ObjectId has to be set to api.Value_DefaultVal star:

    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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大