I am trying to use Dgraph as my primary database. I have a simple system that has two domain entities viz. User
and Product
. They both have certain properties represented as edges/attributes in Dgraph. They both have a common property name which is a string. If I use the same predicate name
for both the nodes then it creates a problem when I am using a has
function to find all the users with a name
edge. The has function also returns Product
nodes with name
edge. This is not desirable.
In this situation, what is the right approach or recommendation when modeling the domain entities? I can think of two approaches:
- Have a common edge
type
for all the nodes to uniquely identify similar nodes. Here the value oftype
would beUser
orProduct
. This is approximately similar to a traditional table/column analogy wheretype
represents thetable
andedges
as columns with a context localized totype
property. - Have a separate predicate for each node type. So, instead of having
name
, prefer two predicates likeuser_name
andproduct_name
.
I believe this problem only exists for RDF/Triplestore databases like Dgraph and not for property graphs like Neo4j since each node contains its own properties.