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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程