简体   繁体   中英

Neo4j/Cypher Query (user action) relationship direction

I am new to Cypher and trying to design a graphic database and store user behaviour. Thanks in advance!

Case Example: 1. A user visited a web page 2. A user owned a device (id:xxxxx)

In UML Class diagram, the arrow (relationship) is pointing toward to parent class

在此处输入图片说明

But, my point of view, not all relationship in Cypher are Parent-Child type, does it means that i should not apply this kind of concept into Cypher?

So, the question is "how to design the direction of relationship"?

(user)-[r:visited]->(webpage {url:xxx})
(user)-[r:owned]->(mobileDevice {uuid:xxx})

-- or --

(user)<-[r:visitedBy]-(webpage {url:xxx})
(user)<-[r:owned]-(mobileDevice {uuid:xxx})

Thank you again

This is a common question. The answer is that it's up to you! Relationship types can be whatever you choose and you should go with what is most comfortable. I would suggest that whatever you do, just try to be consistent.

Personally between "visted" and "visited by", I would go with "visited" because I think it makes more sense to be talking about the fact that the user visited a page, not that a page was visited by the user. I often recommend that people name their relationships so that the node-relationship-node makes a sentence. Since the user is the primary actor your sentence would be "(the) user visited (the) webpage". That might come from me being a native English speaker and the way that English sentences are formed, though.

As a side note, relationships in Neo4j are generally UPPER_SNAKE_CASE . Again, Neo4j doesn't restrict you from any one particular style, but that's what I've seen most. This guide gives a pretty good overview of common Cypher conventions:

http://nigelsmall.com/zen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM