Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-06-2020 07:25 AM
Hi,
I have data structured as in the photo. I wonder how to model this so that I can see the progression of files being worked on by certain users:
file1 was worked on by user1 then user2 then user3
file2 was worked on by user1 then user3 then user2
many thanks in advance
10-06-2020 08:53 AM
IMHO, I think one of the ways is to have the changes arranged in a "linked list":
(f:File)-[:CHANGE]->(c1:Change)-[:NEXT]->(c2:Change)->...-[:CHANGE]->(cn:Change)
Each Change node can contain what are worth to be stored.
Each user is linked to such change that he/she made:
(u1:User)-[:MADE_CHANGE {type: 'Create']->(c1: Change)
(u2:User)-[:MADE_CHANGE {type: 'Edit']->(c1: Change)
...
Of course this approach would make User node to be Supernode if there are large number of users and their edits.
My two cents.
10-06-2020 12:03 PM
Using LOAD CSV, and temporal data types, there are many options. Personally, I would lean toward the following pattern:
See Also: date, datetime, and durations
(:User)<-[:EDITED_BY]-(:File)
It's best to adjust the date-format to follow the built-in standard: YYYY-MM-DD
(can include time: YYYY-MM-DD
THH:MM:SS
ex: 2020-10-06T18:52
). However, you can also use apoc.date.parse, to handle almost any format.
user, file, date_opened
user1, file1, 2020-07-15
user1, file1, 2020-07-16
user1, file2, 2020-07-16
user2, file1, 2020-07-17
user2, file2, 2020-07-20
user3, file1, 2020-07-18
user3, file2, 2020-07-18
Put the csv in the $NEO4J/imports
directory, or on a publicly accessible url.
LOAD CSV WITH HEADERS FROM 'user-edits.csv' AS line
WITH line,
date(line.date_opened) as editDate
MERGE (user :User {name: line.user})
MERGE (file :File {name: line.file})
MERGE (user)<-[edit:EDITED_BY {date: editDate}]-(file)
Since all you asked for was the order users worked on a certain file, I'll collect them into a list for each file:
MATCH (f:File)-[e:EDITED_BY]->(u:User)
WITH f, u ORDER BY e.date ASC
RETURN f.name, collect(u.name) as users
10-07-2020 06:20 AM
Thanks! This is a very neat and straightforward solution!
All the sessions of the conference are now available online