# @upsert directive is important to detect conflicts

**URL:** <https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819>\
**Category:** Dgraph\
**Created:** [June 28, 2018, 6:55am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819 "2018-06-28T06:55:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 28, 2018, 6:55am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/1 "2018-06-28T06:55:17Z")

</div>

i found it doesn’t work.

i tried:

schema:  
“name:string @index(hash) @upsert .\n”

mutate data like

```auto
{
  set {
    
    _:p1 <name> "p1" .
    _:p2 <name> "p2" .
 }
}

```

and then mutate then same:

```auto
{
  set {
    
    _:p1 <name> "p1" .
    _:p2 <name> "p2" .
 }
}

```

it cannot detect the conflicts of name?

what do i miss in using this directive?

---

<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, 7:15am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/2 "2018-06-28T07:15:19Z")

</div>

Here p1 is assigned 2 different uid’s and p2 is also assigned 2 different uid’s.  
For @upsert, if u need to update a node p1 or p2, you should use its uid assigned to p1 or p2 to update accordingly

`https://docs.dgraph.io/master/howto/#upsert-procedure`

---

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 28, 2018, 7:22am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/3 "2018-06-28T07:22:18Z")

</div>

i misunderstand the @upsert, it should work in this situation:  
As such, it’s possible that two concurrently running operations could try to add the same node at the same time

---

<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, 7:28am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/4 "2018-06-28T07:28:59Z")

</div>

Two concurrently running operations could try to add the same node at the same time. In this case, similar nodes will be assigned different uid’s so there would be no conflict.  
@upsert can be done using uid only.  
Hope it clears your doubt.

---

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 29, 2018, 3:08am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/5 "2018-06-29T03:08:50Z")

</div>

ok, i found a situation:  
i set replica=3,  
i have three dgraph server, i insert data to one server, and i can get results from this server, but i cannot get any results in another two server, why?

---

<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 29, 2018, 3:40am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/6 "2018-06-29T03:40:11Z")

</div>

@shanghai-Jerry Can you share your docker-compose.yml file.

---

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 29, 2018, 3:49am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/7 "2018-06-29T03:49:28Z")

</div>

i am not using docker

---

<div class="post-metadata">

**Author:** ![shanghai-Jerry](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/shanghai-jerry/32/863_2.png) [@shanghai-Jerry](https://discuss.dgraph.io/u/shanghai-Jerry)\
**Post date:** [June 29, 2018, 3:55am UTC](https://discuss.dgraph.io/t/upsert-directive-is-important-to-detect-conflicts/2819/8 "2018-06-29T03:55:29Z")

</div>

server one:  
zero

```auto
{
    "idx": 1,
    "my": "172.20.0.8:5080",
    "replicas": 3,
    "wal": "/data/dgraph/zero"
}

```

server config:

```auto
{
    "my": "172.20.0.8:7080",
    "zero": "172.20.0.8:5080",
    "lru_mb": 21440,
    "badger.vlog":"disk"
}

```

server two:

zero:

```auto
{
    "idx": 2,
    "my": "172.20.0.9:5080",
    "peer": "172.20.0.8:5080",
    "replicas": 3,
    "wal": "/data/dgraph/zero",
    "bindall": true
}

```

server config:

```auto
{
    "my": "172.20.0.9:7080",
    "zero": "172.20.0.8:5080",
    "lru_mb": 21440,
    "badger.vlog":"disk"
}

```

server three:  
zero:

```auto
{
    "idx": 3,
    "my": "172.20.0.10:5080",
    "peer": "172.20.0.8:5080",
    "replicas": 3,
    "wal": "/data/dgraph/zero"
}

```

server config:

```auto
{
    "my": "172.20.0.10:7080",
    "zero": "172.20.0.8:5080",
    "lru_mb": 21440,
    "badger.vlog":"disk"
}

```
