# Update does not add uid to api.Assigned uid map, but does update in database

**URL:** <https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084>\
**Category:** Dgraph Clients\
**Tags:** dgo, untagged\
**Created:** [May 11, 2018, 3:24am UTC](https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084 "2018-05-11T03:24:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 11, 2018, 3:24am UTC](https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084/1 "2018-05-11T03:24:51Z")

</div>

**Moved from GitHub [dgo/6](https://github.com/dgraph-io/dgo/issues/6)**

_Posted by_ [nikkon226](https://github.com/nikkon226):

When I try to update, the update does not add the uid to the api.Assigned map, but does update the database.

```
// type model {
// UID string `json:"uid,omitempty"`
// Name string `json:"name,omitempty"`
// }
input := &model{
     UID: "0x1234",
        Name: "Test",
}
inputJson, err := json.Marshal(input)
if err != nil {
	log.Println("error handing json marshal")
	return nil
}
mu := &api.Mutation{
	SetJson: inputJson,
	CommitNow: true,
}
log.Println("mutation object:", mu)
 // mutation object: set_json:"{\"uid\":\"0x1234\",\"name\":\"Test\"}" commit_now:true

txn := o.graph.NewTxn()
defer txn.Discard(ctx)
assigned, err := txn.Mutate(ctx, mu)
if err != nil {
	log.Println("error handing mutation for update")
	return nil
}
log.Println("assigned:", assigned.Uids)
// assigned: map[]
// the database has changed the name to "Test"
if _, ok := assigned.GetUids()[input.ID]; !ok {
	log.Println("update unsuccessful")
	return nil
}
```

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 11, 2018, 6:43pm UTC](https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084/2 "2018-05-11T18:43:05Z")

</div>

[manishrjain](https://github.com/manishrjain) _commented_ :

Unless the UID has been previously allocated, you shouldn’t be using it. In this case, Dgraph thinks that you’re using an allocated UID, and sets the data. Because the UID field wasn’t empty, it didn’t allocate a UID for you.

Don’t pass the UID field, then Dgraph would allocate a UID for you and return it.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 11, 2018, 6:47pm UTC](https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084/3 "2018-05-11T18:47:05Z")

</div>

[nikkon226](https://github.com/nikkon226) _commented_ :

The uid had been previously allocated by dgraph. This is actually part of a bigger issue ([When updating a node, the node's uid isn't returned to signal successful update · Issue #2386 · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/issues/2386)) that comes directly from dgraph where dgraph doesn’t include uids of nodes that have been successfully updated.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 11, 2020, 3:53am UTC](https://discuss.dgraph.io/t/update-does-not-add-uid-to-api-assigned-uid-map-but-does-update-in-database/8084/4 "2020-07-11T03:53:23Z")

</div>


