king conch
king conch

Reputation: 337

Neo4j modeling advice using properties in relationships

I am just getting into Graph databases and need advice.

For this example, I have a 'Person' node and a 'Project' node with two relationships between the two. The two relationships are:

Both are from the Person to the Project.

Specifically referring to using the relationship property to hold the "date value" of the event. Are they any downsides to this, or a better way to model this in a graph?

A simple mock up is below: enter image description here

Upvotes: 1

Views: 88

Answers (2)

Evgen
Evgen

Reputation: 1338

Also think about storing projected finished date and actual finished date in node project in case if this property related to the whole project and is the same for all persons related to it.

This will help you to avoid duplication of data and will make querying projects by properties work faster as you woun't have to look for relationships. In cases where your model designed to have different dates actual and finished for different persons in addition to storing datasets in relationships it still makes sense to store in project Node combined information for the whole project. As it will make model more clear and some queries faster to execute.

Upvotes: 0

Anomaly211
Anomaly211

Reputation: 1103

It is easier to hold dates in the form of Unix Epoch time stamp (stored as long integer), rather than as Julian dates. Neo4j has no built in date / time format.

Timestamp and can be used to perform calculations on the dates to find things like how-many days behind schedule is the project based on current date.

The timestamp() function in Cypher provides a way to get the current Unix time within neo4j.

Each relationship in Neo4J takes up 34 Bytes of data internally, excluding the actual content of the relationship. It might be more efficient to hold both scheduled completion and verified completion as properties in a single relationship rather than storing them as two relationships.

A relationship does not need to have both the scheduled date and the verified date at the same time (the advantages of NoSQL). You can add the verified date later using the SET keyword.

Just to give you an example.

use the following Cypher statement to create.

Create (p:Person {name:'Bill'})-[r:Works_On {scheduledcompletion: 1461801600}]->(pro:Project {name:'Jabberwakie'})

use the following Cypher statement to set the verified date to current time.

Match (p:Person {name:'Bill'})-[r:Works_On]->(pro:Project {name:'Jabberwakie'}) set r.verifiedcompletion=timestamp()

use the following Cypher statement to perform some kind of calculation, in this case to return a boolean value if the project was behind schedule or not.

Match (p:Person {name:'Bill'})-[r:Works_On]->(pro:Project {name:'Jabberwakie'}) return case when r.scheduledcompletion > r.verifiedcompletion then true else false end as behindschedule

Upvotes: 3

Related Questions