# Create or Update a node

**URL:** <https://discuss.dgraph.io/t/create-or-update-a-node/2832>\
**Category:** Dgraph\
**Created:** [June 28, 2018, 12:19pm UTC](https://discuss.dgraph.io/t/create-or-update-a-node/2832 "2018-06-28T12:19:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgupta](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@rgupta](https://discuss.dgraph.io/u/rgupta)\
**Post date:** [June 28, 2018, 12:19pm UTC](https://discuss.dgraph.io/t/create-or-update-a-node/2832/1 "2018-06-28T12:19:41Z")

</div>

I found this that will create or update a node/vertex [https://docs.dgraph.io/howto/#upsert-procedure](https://docs.dgraph.io/howto/#upsert-procedure)

I tried to search for documentation with sample queries but I am not getting any sample query.

Are there any better alternatives? to Upsert

---

<div class="post-metadata">

**Author:** ![karan28aug](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@karan28aug](https://discuss.dgraph.io/u/karan28aug)\
**Post date:** [June 28, 2018, 2:50pm UTC](https://discuss.dgraph.io/t/create-or-update-a-node/2832/2 "2018-06-28T14:50:39Z")

</div>

```auto
p := Person{
    Name: "Bob",
    Age: 24,
}

txn := dg.NewTxn()
pb, err := json.Marshal(p)
if err != nil {
    log.Fatal(err)
}

mu := &api.Mutation{
    CommitNow: true,
    SetJson: pb,
}
assigned, err := txn.Mutate(ctx, mu)
if err != nil {
    log.Fatal(err)
}
bob := assigned.Uids["blank-0"]

p = Person{
    Name: "Alice",
    Age: 26,
    Married: true,
    Raw: []byte("raw_bytes"),
    Friends: []Person{{
        Uid: bob,
    }, {
        Name: "Charlie",
        Age: 29,
    }},
    School: []School{{
        Name: "Crown Public School",
    }},
}

```

You can use this to create and update a node.
