# Update list of uids

**URL:** <https://discuss.dgraph.io/t/update-list-of-uids/10682>\
**Category:** Dgraph\
**Tags:** kind:question, dgraph\
**Created:** [September 29, 2020, 11:32pm UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682 "2020-09-29T23:32:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vnium](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vnium](https://discuss.dgraph.io/u/vnium)\
**Post date:** [September 29, 2020, 11:32pm UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682/1 "2020-09-29T23:32:03Z")

</div>

I am trying to update a list of uids in Dgraph via DQL.

```auto
uidList: [uid] .

type DummyType {
uidList
}

```

So for example I want to update an already existing uid list (predicate `uidList`) consisting of `0x1, 0x2, 0x3` to `0x5, 0x6, 0x7, 0x8`.

I am using the Golang client Dgo. Is the above possible in one transaction/call? Currently I have to first delete the existing list and after that set the new elements.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [September 29, 2020, 11:44pm UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682/2 "2020-09-29T23:44:45Z")

</div>

1. If you know the UID of the target entity.

Do the mutation with its uid.

```auto
<0x0fff34> <uidList> <0x5> .
<0x0fff34> <uidList> <0x6> .
<0x0fff34> <uidList> <0x7> .
<0x0fff34> <uidList> <0x8> .

```

1. If you don’t know the UID but you know how to find it.

```auto
upsert {
  query {
     v as q(func: eq(username, "NAME))
  }

  mutation {
    set {
      uid(v) <uidList> <0x5> .
      uid(v) <uidList> <0x6> .
      uid(v) <uidList> <0x7> .
      uid(v) <uidList> <0x8> .
    }
  }
}

```

1. f you wanna remove the `0x1, 0x2, 0x3`.

```auto
{ 
  delete {
      <0x0fff34> <uidList> <0x1> .
      <0x0fff34> <uidList> <0x2> .
      <0x0fff34> <uidList> <0x4> .
   }
}

```

And now

```auto
{ 
  set {
       <0x0fff34> <uidList> <0x5> .
       <0x0fff34> <uidList> <0x6> .
       <0x0fff34> <uidList> <0x7> .
       <0x0fff34> <uidList> <0x8> .
   }
}

```

1. f you wanna remove the `0x1, 0x2, 0x3` and set the new relations, but you don’t know the uid.

```auto
upsert {
  query {
     v as q(func: eq(username, "NAME))
  }

  mutation {
    set {
      uid(v) <uidList> <0x5> .
      uid(v) <uidList> <0x6> .
      uid(v) <uidList> <0x7> .
      uid(v) <uidList> <0x8> .
    }
    delete {
      uid(v) <uidList> <0x1> .
      uid(v) <uidList> <0x2> .
      uid(v) <uidList> <0x4> .
   }
  }
}

```

---

<div class="post-metadata">

**Author:** ![vnium](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vnium](https://discuss.dgraph.io/u/vnium)\
**Post date:** [September 30, 2020, 8:01am UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682/3 "2020-09-30T08:01:23Z")

</div>

Thank you for the help. I tested your code and it works as expected.

Is it also possible to delete all edges without knowing the uids and after that insert the new edges? I tried the mutation below, but it seems the delete block is executed after the set block, so I end up with no edges at all.

```auto
upsert {
  query {
     v as q(func: eq(username, "NAME))
  }

  mutation {
    delete {
      uid(v) <uidList> * .
    }
    set {
      uid(v) <uidList> <0x5> .
      uid(v) <uidList> <0x6> .
      uid(v) <uidList> <0x7> .
      uid(v) <uidList> <0x8> .
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [September 30, 2020, 3:25pm UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682/4 "2020-09-30T15:25:47Z")

</div>

Humm, not sure. Feels like the order of the operations doesn’t matter. You can do in two rounds.

You can also try.

```auto
upsert {
  query {
     v as q(func: eq(username, "NAME"))
  }
  mutation {
    delete {
      uid(v) <uidList> * .
    }
  }
  mutation {
    set {
      uid(v) <uidList> <0x5> .
      uid(v) <uidList> <0x6> .
      uid(v) <uidList> <0x7> .
      uid(v) <uidList> <0x8> .
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![vnium](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vnium](https://discuss.dgraph.io/u/vnium)\
**Post date:** [September 30, 2020, 9:10pm UTC](https://discuss.dgraph.io/t/update-list-of-uids/10682/5 "2020-09-30T21:10:05Z")

</div>

That worked, thank you.
