Error: code = Unknown desc = Operation must have at least one field set

Hi
#golang #dgo #go
I create a func mutate in go for mutate the RDF ,
and send argument from main to func mutate

my code :

package main

import (
    "context"
    "log"
    "fmt"
    "github.com/dgraph-io/dgo"
    "github.com/dgraph-io/dgo/protos/api"
    "google.golang.org/grpc"
)


func mutate(dg *dgo.Dgraph, ctx context.Context) {
    mu := &api.Mutation{
        CommitNow: true,
    }
    p := `
        _:person1 <UrlName> "mahdi999" .
        _:person2 <UrlName> "ali" .
    `
    mu.SetNquads = []byte(p)
    _, err := dg.NewTxn().Mutate(ctx, mu)
    if err != nil {
        log.Fatal(err)
    }
    resp, err := dg.NewTxn().Query(context.Background(), `{
    find(func: has(UrlName)) {
        UrlName
    }
    }`)
  
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Response: %s\n", resp.Json)
}


func main() {
    conn, err := grpc.Dial("127.0.0.1:9080", grpc.WithInsecure())
    if err != nil {
        log.Fatal("trying to dial gRPC")
    }
    defer conn.Close()

    dc := api.NewDgraphClient(conn)
    dg := dgo.NewDgraphClient(dc)

    op := &api.Operation{}      // DropAll : true
    ctx := context.Background()
    err = dg.Alter(ctx, op)
    if err != nil {
        log.Fatal(err)
    }
    mutate(dg , ctx)
}

But when run the go show this error :

2019/09/14 15:19:20 rpc error: code = Unknown desc = Operation must have at least one field set
exit status 1

Can you help me ?!

op := api.Operation{DropAll: true}

i don’t want drop all data .
how to don’t drop data and mutate in dgraph with go .
in python i can mutate and don’t drop data in database .

How about not running dg.Alter(ctx, op) at all? You shouldn’t need it if you just want to mutate.