Databases Reference
In-Depth Information
START email = node :email( id = '11' )
MATCH (email)<-[f:FORWARD_OF*]-()
RETURN count (f)
This query starts at the given email and then matches against all incoming FOR
WARD_OF relationships to any depth. These relationships are bound to an identifier f . To
calculate the length of the email chain, we count the number of FORWARD_OF relationships
bound to f using Cypher's count function. In this example, we see the original email
has been forwarded twice:
+----------+
| count(f) |
+----------+
| 2 |
+----------+
1 row
Avoiding Anti-Patterns
In the general case, don't encode entities into relationships. Use relationships to convey
semantics about how entities are related, and the quality of those relationships. Domain
entities aren't always immediately visible in speech, so we must think carefully about
the nouns we're actually dealing with.
It's also important to realize that graphs are a naturally additive structure. It's quite
natural to add facts in terms of domain entities and how they interrelate using new
nodes and new relationships, even if it feels like we're flooding the database with a great
deal of painstaking data. In general, it's bad practice to try to conflate data elements at
write time to preserve query-time efficiency. If we model in accordance with the ques‐
tions we want to ask of our data, an accurate representation of the domain will emerge.
With this data model in place, we can trust the graph database to do the right thing.
Graph databases maintain fast query times even when storing vast
amounts of data. Learning to trust our graph database is important
when learning to structure our graphs without denormalizing them.
Summary
Graph databases give software professionals the power to represent a problem domain
using a graph, and then persist and query that graph at runtime. We can use graphs to
clearly describe a problem domain; graph databases then allow us to store this repre‐
sentation in a way that maintains high affinity between the domain and the data. Further,
graph modeling removes the need to normalize and denormalize data using complex
data management code.
Search WWH ::




Custom Search