I am using the Python client. When I run the following code twice, two exact same duplicates of the nodes are created in my graph, except that they have different uids, even though I have specified the uids in the mutation data. How can I ensure that the same data isn’t added twice?
But I don’t understand - what is the point of me setting the UIDs if I can’t even use them then? Why is there an option to set the UID if it just seems to be overwritten by a UID generated by Dgraph when the node is created?
To your question of why it adds two nodes with the same information, the way you are using blank nodes is not going to achieve what you want it to. Let me try to explain how blank nodes work.
Blank nodes syntax is used when you are agnostic to what uid is assigned to the nodes which you are creating. Therefore you use blank nodes to just identify the same node while adding more predicates to it. Using @Neeraj’s example I added one more property to each node and I referenced that node by using the blank node syntax
but there will be couple of issues going that way:
You don’t know the uid-of-device unless you create the device node in the same way.
Bigger problem is you can’t assign uids without leasing them from zero. You would have to hit /assign end point before assigning the uids and ensure that the uids you want to assign fall inside the range that you leased.
Since you already have the fields like customer-id, phone-id etc. in your schema I would suggest use conditional upserts like @ibrahim suggested. Another way is using xids. You can read about them here.