Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-01-2020 10:21 PM
Hi Team,
I was playing with the Neo4j, and came across where i have to store historical data of a Customer.
Like a Customer is Subscribed to a site with some preferences on 01-JAN-2020, and later say in 20-JAN-202 the Customer has changes his some of the preferences, and further he changed again, and currently he is having x numbers of preferences.
How to handle this?
Do we need to have a node for each changed data? if so what is the best way to have it?
Solved! Go to Solution.
03-02-2020 09:25 AM
The behavior you are asking for would not be useful to most applications of Neo4j, but would significantly increase the resource usage for any db instance. For that reason, preserving history is not built into Neo4j.
However, there are many ways you can recover data history. Most efficiently, with Transaction Logs, but will require careful development to generate pretty views, or make nodes restorable. Alternatively, every time you change a node, you can write your Cypher to preserve the old node(s).
Your node history could be a chain of relationships:
(current)-[:PREV]->(old)-[:PREV]->(old)...
Or you could put dates/user on those relationships, and have all past versions as children of the current:
(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'me'}]->(old)
(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'you'}]->(old2)
// new
CREATE (old3)<-[HISTORY {date: (now); user: (self)]-(current)
SET old3 = current
SET current = new
Moral of the story, Neo4j gives you an engine, but It's up to you to make that engine do what you want it to.
03-02-2020 12:39 AM
Hi Mayank,
We can store any information either as node or as properties of node and it's design will be driven by the reports you need.
Regards
Vivek
03-02-2020 08:14 AM
Agreed with this.. but my confusion is, do we have to create another node when the property of a node changes, to maintain the history of that node, or there is any internal versioning which keeps track of any changes to properties of a node, and when required we can have it.
03-02-2020 09:25 AM
The behavior you are asking for would not be useful to most applications of Neo4j, but would significantly increase the resource usage for any db instance. For that reason, preserving history is not built into Neo4j.
However, there are many ways you can recover data history. Most efficiently, with Transaction Logs, but will require careful development to generate pretty views, or make nodes restorable. Alternatively, every time you change a node, you can write your Cypher to preserve the old node(s).
Your node history could be a chain of relationships:
(current)-[:PREV]->(old)-[:PREV]->(old)...
Or you could put dates/user on those relationships, and have all past versions as children of the current:
(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'me'}]->(old)
(current)-[:HISTORY {date: 'yyyy-mm-dd'; user: 'you'}]->(old2)
// new
CREATE (old3)<-[HISTORY {date: (now); user: (self)]-(current)
SET old3 = current
SET current = new
Moral of the story, Neo4j gives you an engine, but It's up to you to make that engine do what you want it to.
11-27-2022 03:30 AM
Hi Mayank,
Recently I am working with neo4j for my final project. I have also the same problem as you asked. Did you get any proper way for this problem. Please let me know.
All the sessions of the conference are now available online