How to make composit keys in Dgraph

Sometimes we will encounter the same city name in different provinces, or the street with the same name in different cities, at this time using a single city name or street name as the key will not be recognized. Cassandra allows users to use key1: key2 to store a pair of values as key, such as <userid: lastupdate> to store userid and last login time, which is called composit keys. How to express this composite situation in dgraph?

Feels like you have two questions. One about an issue with city “collisions” names and other a question about composite keys. Is it right?

In Dgraph we don’t have the concept of composite keys. But you could try facets to try to simulate that.

About the city names. You could create a tree just for places. A tree with relations. Like “Country => State => Region || province => City => Neighborhood || district => Street => Building || gated community => Block”. A cognitive tree (similar to a knowledge graph). And then relate the person to the last object in the tree.

Through such a custom tree you can create important data that can be easily read(and displayed in graphs). Like “How many people live in NY”. That would be easy to know because using “count” you would have this value already set. Instead of doing an extensive query with aggregations.

Just adding to what @MichelDiz said, you could also just build the tree in Dgraph using predicates (no facets). Because each node has a unique UID, even when city names are same, they will be represented using different nodes in Dgraph with different UID. You could then use a combination of root query and filters to find the correct node that you are interested in.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.