简体   繁体   中英

Versioning relationships between nodes in neo4j

Lets say there are two nodes A and B,

(A)-[r]-(B)

r has a property 'weight', that is a measure of dependency of A on B, let's say.

The value of weight frequently changes, and I wish to version the value of weight. Is it feasible to make a new relationship between the two same nodes, and add a property ['valid': true] on the relationship created last?

I ask this question because I was told that if I need versioning on properties, they should definitely be nodes:

https://twitter.com/ikwattro/status/746997161645187072

But, the weight property between the two nodes A and B naturally belongs to the relationship between them. How do use a node to maintain the weight?

EDIT:

An example: Let A be a node with label :FRUIT, and B be a node of label :PERSON Further, let r be a relationship between the two, with a label :LIKING, and, the 'weight' property of r be a measure of how much person B likes fruit A.

The weight property of r keep changing, and it is required to version this property with time.

I think this depends on two things: The frequency of weight updates and the queries you will run on the versioned weights :

  1. If you expect a smallish number of updates and if only keep them for reference, you could use a single relationship and store the old values in a property (eg a map or even a string).

  2. If you expect a smallish number of updates and if you want to query the data regularly, it would be reasonable to use new relationships for each update.

  3. If the weight changes frequently and you actually need to access the data (ie collect millions of weight values for millions of fruits), I would not store it in neo4j. Use a simple MySQL table with PersonID, FruitID, weight, timestamp or some other data store. Store only the latest value in neo4j.

I use both 2. and 3. a lot and even though 3. sounds overkill it's usually simple to implement as long as you only 'outsource' structured data with clear queries.

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