Reputation: 11
How would you model the places visited by 2 or more people on a given date? Seems like it should be pretty simple but I don't get how to relate them to be able to say, User 1 and User 2 visited X on y date or how to say they visited X together on the same date.
I started this GraphViz to help visualise it:
digraph visit_example {
node [shape = doublecircle]; "User 1" "User 2";
node [shape = circle];
"User 1" -> Alaska [ label = "Visits" ];
"User 2" -> Alaska [ label = "Visits" ];
"Jan 1st" -> Date [label = "is a"];
"Mar 7th" -> Date [label = "is a"];
"Dec 9th" -> Date [label = "is a"];
}
How would you change the above to say, User 1 visited Alaska on March 7th with User 2? Independently, User 1 visited Alaska on Jan1st and User 2 on Dec 9th?
Upvotes: 1
Views: 69
Reputation: 20185
The advantage (and sometimes inconvenient) of a graph database is that such use cases can be modeled in multiple fashions.
It depends also on what kind of queries you would want to do.
Let's say, you'll never query by time and if you would do, query time is not important, you can easily put the date on the relationship property.
(a:User)-[:VISITED {time:0123456789}]->(p:Place)
If, you want to query by date, then you can for e.g., have a :Visit node representing the visit of the user and have a time property on it
(a:User)-[:DO_VISIT]->(v:Visit {time: 123456789})-[:IN_PLACE]->(p:Place)
Then you can query all :Visit
nodes by time
Another solution is to manage a time tree, for e.g. GraphAware's TimeTree
Then your Visit node will be automatically attached to a TimeTree
(:Year {value:2015})-[:CHILD]->(:Month {value:7})-[:CHILD]->(:Day {value:8})<-[:EVENT_TIME]-(v:Visit)<-[:DO_VISIT]-(:User)
There are certainly other ways to model it, try the one that best fit your needs and performance of queries
Upvotes: 2