External ID Functionality

Hi, so I have read the documentation on https://dgraph.io/docs/v1.0.7/mutations/#external-ids, which more describes their technical usage. To take a step back, can u please help me understand why someone would use in first place?
So I get the premise, that for a given node we want to model may already has an identifier from another system that we want to reuse. Also, for dgraph nodes we must always use a uid. So let us say my (external) identifier is called fooId, what are the pros / cons of modelling fooId as a “regular” indexed attribute on the “foo” node vs implementing as an external Id? What I am so far deducing from the above linked documentation:

  1. its more convenient for build queries using xid
  2. its more involved to implement an xid

Q. Does xid help/force node uniqueness?

=======================

As a followup question, (re point 2 above), I have so far being using Java with JSON (as opposed to RDF) for my dgraph mutations. Could I get a tip on how to implement xid? (For a facet, the following works nice)

@SerializedName(“mt_rel_name|factetName”)
String factetName;

Thanks!

There are several cases. But the intention behind that part of the docs is based on RDF standards. I mean, RDF is usually used in ontology data. And save this info as an entitie guarantees that info is not lost. And makes possible to simulate some ontology patterns.

External ID in this case is like a theoretical indexing via edges. Where you can give more information for this indexing by adding attributes. When indexing via a single attribute, you cannot add extra information unless using facets. But in that case, the information would have to be replicated in all nodes that contain this attribute.

With an entity you can share the same context of information among several other nodes. And basically, as all nodes are connected to that entity. You have an “indexing” out of the box.

No, and yes. In practice, you have to create the entity and connect all your nodes to it. There is no way to guarantee that you will not accidentally create duplicate entities. Unless you use upsert.

There is no guarantee of uniqueness in Dgraph and external IDs wasn’t thought of with this proposal. Only using Upsert will you achieve this.

Not sure if I got the question. Can you elaborate?

1 Like

Thanks. I will elaborate. Ill put some code together first and get back to u…