# Uid cannot be greater than

**URL:** <https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113>\
**Category:** Dgraph\
**Tags:** kind:question\
**Created:** [September 8, 2020, 3:52pm UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113 "2020-09-08T15:52:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 8, 2020, 3:52pm UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/1 "2020-09-08T15:52:47Z")

</div>

first

```auto
curl -H "Content-Type: application/json" "localhost:8080/mutate?commitNow=true" -XPOST --data-binary @organisation_0_0.json | python -m json.tool | less

```

get error

```auto
"Uid: [18444291013291836287] cannot be greater than lease: [10000000000000020000]"

```

but

 ![image](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/7/7210bb5928617c168cdd4f700b03cb7c6d08fb64.png)

!!  
why!!  
my data like

```auto
{"dgraph.type": "company", "name": "Kam_Air", "url": "http:\\/\\/dbpedia.org\\/resource\\/Kam_Air", "uid": "0xfff748f45d30837f"}

```

why!!  
what else can I do?

---

<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 8, 2020, 4:57pm UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/2 "2020-09-08T16:57:06Z")

</div>

> [@youyin123](#):
>
> why!!  
> what else can I do?

Your dataset has `"uid": "0xfff748f45d30837f"` this means that Dgraph should search for an existing entity with this UID and mutate there. But as this UID doesn’t exists, Dgraph will fail.

You have three options.

Option 1: Remove the UID from the dataset.

Option 2: Transform them into blank nodes adding in front the prefix `_:` e.g. `"uid": "_:0xfff748f45d30837f"` that way you will have a new uid.

> Pay attention that blank nodes works at the transaction level. It won’t give you unique UIDs all the time you create a new transaction. You have to handle this yourself.

Option 3: Lease a huge amount of uids from `/assign?what=uids&num=` see the docs for more details [More about Dgraph Zero - Deploy](https://dgraph.io/docs/deploy/dgraph-zero/) - If this doesn’t work in the first try. Keep creating more UIDs.

---

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 9, 2020, 2:09am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/3 "2020-09-09T02:09:31Z")

</div>

> [@MichelDiz](#):
>
> Your dataset has `"uid": "0xfff748f45d30837f"` this means that Dgraph should search for an existing entity with this UID and mutate there. But as this UID doesn’t exists, Dgraph will fail.

> Blockquote

you mean I can’t set uid by myself ？？  
but same code in my Mac it worked, run in server is error …

---

<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 9, 2020, 2:11am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/4 "2020-09-09T02:11:59Z")

</div>

> [@youyin123](#):
>
> you mean I can’t set uid by myself ？？

Yep.

> [@youyin123](#):
>
> but same code in my Mac it worked, run in server is error …

Your Mac and your Server are two different environments. So, in the server, for sure it doesn’t have the UID `0xfff748f45d30837f` leased.

---

<div class="post-metadata">

**Author:** ![BlankRain](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/blankrain/32/1592_2.png) [@BlankRain](https://discuss.dgraph.io/u/BlankRain)\
**Post date:** [September 9, 2020, 2:27am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/5 "2020-09-09T02:27:57Z")

</div>

uid 由zero 统一分配  
可以根据uid 更新数据,但是uid得已经存在了.

---

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 9, 2020, 2:38am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/6 "2020-09-09T02:38:04Z")

</div>

@BlankRain确定不能自己设置吗？？

---

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 9, 2020, 4:35am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/7 "2020-09-09T04:35:25Z")

</div>

@MichelDiz  
for example, Data include：  
people.json (node)  
people\_like\_perople.json (edge)

question:

1. due to data is big(\>100000000), should I used bulk to loading?

2. because people\_like\_perople.json contains the nodes in people.json，in order to avoid duplication，what should I do ?  
（if I load people.json first ,then load people\_like\_perople.json couldn’t use bulk;  
but if I load them together, then it will have duplication node;  
if I put them in one file, this file is so so so big I don’t want to do…）

3. bulk way I don’t know how to do it, even if I read the document…

4. Although I can import data correctly in HTTP mode, I want to do dgraph performance evaluation, so I need to import data in the fastest way so that the evaluation result is correct, right?  
Which of the following three methods is the fastest to import data?

```auto
curl -H "Content-Type: application/json" "localhost:8080/mutate?commitNow=true" -XPOST --data-binary @organisation_0_0.json | python -m json.tool | less

```

```auto
    dgraph live -f organisation_0_0.json -s schema

```

```auto
    dgraph bulk -f organisation_0_0.json -s schema

```

---

<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 9, 2020, 5:07am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/8 "2020-09-09T05:07:45Z")

</div>

What I recommend to avoid duplicates is.

1. Start your cluster from scratch with as many datasets as possible using Bulkloader. And use xidmap feature to save the Blank Node(the RDF identifier) mapping on directory.

```auto
dgraph bulk -h | grep xidmap
      --xidmap string Directory to store xid to uid mapping

```

1. Later on, you gonna use Liveloader to ingest a big amount of data that you can’t handle yourself at the client. But you need those references, and maybe create new ones (I’m talking about Blank nodes mapping). Liveloader also has the flag xidmap.

To reuse the same blank nodes once mapped on your first ingestion with bulkload, you have to start the live load always point to the same path/folder that you have started the xid mapping in the Bulkloader.

```auto
dgraph live -h | grep xidmap
      --xidmap string Directory to store xid to uid mapping

```

So, what do you solve with this approach? basically any duplication of entities. You don’t need to rely on UIDs or something else. Once the Blank node is mapped. If you always use the same blank nodes and the same xid mapping path. You are good to go.

> [@youyin123](#):
>
> Which of the following three methods is the fastest to import data?

The bulkloader is the fastest. But you can only use it once.

Liveloader is your best friend, it will deal better with the data avoiding early OOM in case of a machine with low resources.

Never, ever, use the HTTP API for big datasets. This will congest your cluster and possibly giving OOM on the medium run.

You could use the HTTP API, but with small batches, even if it continuous events.

---

<div class="post-metadata">

**Author:** ![youyin123](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/youyin123/32/4685_2.png) [@youyin123](https://discuss.dgraph.io/u/youyin123)\
**Post date:** [September 9, 2020, 5:46am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/9 "2020-09-09T05:46:07Z")

</div>

@MichelDiz

1. All my data is JSON, so I can use xidmap, right?
2. In fact, I noticed the – xidmap command at the beginning, but what I understood was to save the uid mapping of the imported data. I don’t see how to use the saved mapping on the next import. Do you mean to save and use both are – xidmap command ?

when save:

```auto
dgraph live -f organisation_0_0.json -s schema --xidmap /myfolder/xidmap

```

when use:

```auto
dgraph live -f organisation_0_0.json -s schema | grep xidmap /myfolder/xidmap

```

right??

---

<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 9, 2020, 5:57am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/10 "2020-09-09T05:57:36Z")

</div>

> [@youyin123](#):
>
> All my data is JSON, so I can use xidmap, right?

Yes.

> [@youyin123](#):
>
> I don’t see how to use the saved mapping on the next import.

You have to re-use the saved files.

> [@youyin123](#):
>
> right??

First:

```auto
dgraph bulk -f myBaseDataset.json -s base.schema --xidmap ./myfolder/xidmap

```

And then (start to always use the xidmap)

```auto
dgraph live -f newdata1.json --xidmap ./myfolder/xidmap

```

You don’t need to give a schema if the data has the same structure from the previous. Only give the schema if the data has new entities or you wanna change the schema.

That’s really all.

---

<div class="post-metadata">

**Author:** ![BlankRain](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/blankrain/32/1592_2.png) [@BlankRain](https://discuss.dgraph.io/u/BlankRain)\
**Post date:** [September 9, 2020, 7:25am UTC](https://discuss.dgraph.io/t/uid-cannot-be-greater-than/10113/11 "2020-09-09T07:25:11Z")

</div>

bulk 导入的时候 -f . 就可以了 把数据都放一块  
可以先把json转rdf,相同的数据生成相同的标示就不会重复了
