# How to implement custom id to replace uid, and different nodes are associated according to id

**URL:** <https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539>\
**Category:** Dgraph\
**Created:** [July 5, 2020, 8:32am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539 "2020-07-05T08:32:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandalive](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pandalive/32/3455_2.png) [@pandalive](https://discuss.dgraph.io/u/pandalive)\
**Post date:** [July 5, 2020, 8:32am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/1 "2020-07-05T08:32:13Z")

</div>

I plan to generate a unique id to replace uid based on twitter’s snowflake algorithm. And all nodes are associated according to id, not uid.

please help me.

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [July 5, 2020, 8:55am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/2 "2020-07-05T08:55:55Z")

</div>

> [@pandalive](#):
>
> And all nodes are associated according to id, not uid.

You can’t replace `uids` because that is internally used by dgraph for processing. You can look into [assigning `xids`](https://dgraph.io/docs/mutations/#external-ids) to each node based on your algorithm.

---

<div class="post-metadata">

**Author:** ![pandalive](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pandalive/32/3455_2.png) [@pandalive](https://discuss.dgraph.io/u/pandalive)\
**Post date:** [July 5, 2020, 9:31am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/3 "2020-07-05T09:31:16Z")

</div>

@Anurag  
Oh,so sad. If I give up dgraph in the future, maybe this is one of the reasons…

How to associate between xid?

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [July 5, 2020, 10:01am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/4 "2020-07-05T10:01:34Z")

</div>

`xid` can be treated like just another predicate. From the docs [here](https://dgraph.io/docs/mutations/#external-ids)

```auto
<0x123> <xid> "http://schema.org/Person" .

```

---

<div class="post-metadata">

**Author:** ![pandalive](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pandalive/32/3455_2.png) [@pandalive](https://discuss.dgraph.io/u/pandalive)\
**Post date:** [July 5, 2020, 10:17am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/5 "2020-07-05T10:17:24Z")

</div>

Yeah. I know, I mean is it possible to create edge by xid instead of uid ?

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [July 5, 2020, 10:49am UTC](https://discuss.dgraph.io/t/how-to-implement-custom-id-to-replace-uid-and-different-nodes-are-associated-according-to-id/7539/6 "2020-07-05T10:49:04Z")

</div>

Not directly but you can search for nodes with some `xid`, save `uid` of those nodes in a variable and then create edges using that variable. See section: External IDs and Upsert Block in the [docs](https://dgraph.io/docs/mutations/#external-ids-and-upsert-block).

```auto
   upsert {
      query {
        var(func: eq(SOME_XID, "Robin Wright")) {
          Person as uid
        }
      }
      mutation {
          set {
           uid(Person) <xid> SomeXID .
           uid(Person) <edge1> something something .
           uid(Person) <edge2> something something .
           uid(Person) <dgraph.type> SomeType .
          }
      }
    }

```
