Two nodes are getting created even if uid is same in the mutation

My mutation data

[
  {
    "dgraph.type": "Candidate",
    "uid": "_:NCS_Candidate",
    "userId": "NCS",
    "HAS_SKILL": [
      {
        "dgraph.type": "Skill",
        "uid": "_:UX\\\\UI",
        "name": "UX\\UI"
      },
      {
        "dgraph.type": "Skill",
        "uid": "_:UX\\\\UI",
        "name": "UX\\\\UI"
      },
      {
        "dgraph.type": "Skill",
        "uid": "_:UX__UI",
        "name": "UX\\UI"
      }
    ]
  }
]



]

I have used the below live loader command

dgraph live -f /home/sample.json -U  xid

when I load the file for first time , I see 2 skills which I expected

When I load the same file for 2nd time , I see 3 skills
each time I load this file , I see extra skill
output:

{
  "data": {
    "q": [
      {
        "userId": "NCS",
        "uid": "0x3a349248",
        "HAS_SKILL": [
          {
            "name": "UX\\UI",
            "uid": "0x3a349249",
            "xid": "_:UX\\\\UI"
          },
          {
            "name": "UX\\UI",
            "uid": "0x3a34924a",
            "xid": "_:UX__UI"
          },
          {
            "name": "UX\\\\UI",
            "uid": "0x3a66eceb",
            "xid": "_:UX\\\\UI"
          },
          {
            "name": "UX\\\\UI",
            "uid": "0x3a9ace2c",
            "xid": "_:UX\\\\UI"
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 171495,
      "processing_ns": 913917,
      "encoding_ns": 62188,
      "assign_timestamp_ns": 1104088,
      "total_ns": 2346467
    },
    "txn": {
      "start_ts": 11301657
    },
    "metrics": {
      "num_uids": {
        "HAS_SKILL": 1,
        "_total": 20,
        "name": 4,
        "pk": 5,
        "uid": 5,
        "userId": 1,
        "xid": 4
      }
    }
  }
}

I have given same uid with 2 different name values, so the name should overWrite but instead I see duplicate node each time.
Why is this happening?
What is difference between xid and uid?
Even i give same uid value why i am seeing different uid numbers in the output?

Hi @Mounika_Mandadi
Here HAS_SKILL is your edge and the problem is that you cannot connect a node to another node twice with the same predicate name(HAS_SKILL).

If I try to connect twice , it should override right?
How can it create two nodes on explicit mention of uid value? @pshaddel

No, Take a look at this part of docs:

The blank node labels _:class, _:x and _:y do not identify the nodes after the mutation, and can be safely reused to identify new nodes in later mutations.

https://dgraph.io/docs/mutations/blank-nodes/

@pshaddel if that is the case then , “uid”: “_:UX__UI”, this node should also get duplicated right, but that is merging properly even though it is blank uid

@Mounika_Mandadi Actually that is not the case. This pattern _:identifier will tell dgraph that I want to create a new node and return the uid in the result and I might want to reuse it somewhere else in the current query.

We want to create a blog post and we want to create javascript and c# Tag at the same time.

{
 "set":[
  {
    "dgraph.type": "BlogPost",
    "uid": "_:first_blog",
    "title": "Frontend Guide",
    "tags": [
      {
        "dgraph.type": "Tag",
        "uid": "_:js",
        "name": "javascript"
      }
    ]
    },
    {
    "dgraph.type": "BlogPost",
    "uid": "_:second_blog",
    "title": "Frontend Guide",
    "tags": [
      {
        "dgraph.type": "Tag",
        "uid": "_:js",
        "name": "javascript"
     },
     {
        "dgraph.type": "Tag",
        "uid": "_:c#",
        "name": "C Sharp"
     }
    ]
  }
]

By using _:js I’m telling dgraph that these two blog posts should be connected to javscript tag. If I didn’t use _:js Dgraph would have generated two different javascript tag.

I hope it would help you understand the logic.

@pshaddel I understood that logic. will the same be applied in case of live loading of data using live loader?

Yes it supports:

Dgraph Live Loader correctly handles assigning unique IDs to blank nodes across multiple files, and can optionally persist them to disk to save memory, in case the loader was re-run.

https://dgraph.io/docs/deploy/fast-data-loading/live-loader