Neo4J - Saving links between nodes

I was wondering if there are any advantages or disadvantages to storing data in relationships or nodes.

For example, if I have to store comments related to a discussion in the database, should I store the comment data in a “comment” or “comment” node, which is associated with the discussion through a separate relationship.

+4
source share
1 answer

The correct data model depends on the types of queries that must be completed. You must find out what your queries are, and then determine the data model that meets these criteria:

  • It allows you to answer all your inquiries,
  • ,
  • .

, , , . , , ( , ).

. , , ( c1): [c1, c3] [c1, c2, c4]. , , .

, :

(u1:User {name: "A"})-[:MADE]->(c1:Comment {time:0, text: "Fee"})-[:ABOUT]->(s1:Subject {title: "Jack"})
(u2:User {name: "B"})-[:MADE]->(c2:Comment {time:1, text: "Fie"})-[:ABOUT]->(c1)
(u3:User {name: "C"})-[:MADE]->(c3:Comment {time:3, text: "Foe"})-[:ABOUT]->(c1)
(u4:User {name: "D"})-[:MADE]->(c4:Comment {time:9, text: "Fum"})-[:ABOUT]->(c2)

, - , BIG FLAW. , ( 2-4). neo4j, .

(u1:User {name: "A"})-[c1:COMMENTED_ABOUT {time:0, text: "Fee"}]->(s1:Subject {title: "Jack"})
(u2:User {name: "B"})-[c2:COMMENTED_ABOUT {time:1, text: "Fie"}]->(c1)
(u3:User {name: "C"})-[c3:COMMENTED_ABOUT {time:3, text: "Foe"}]->(c1)
(u4:User {name: "D"})-[c4:COMMENTED_ABOUT {time:9, text: "Fum"}]->(c2)

, , , .

, , ( WHERE ):

MATCH p=(s:Subject)<-[:ABOUT*]-(c:Comment)<-[m:MADE]-(u:User)
WHERE NOT (c)<-[:ABOUT]-()
RETURN p
+9

All Articles