Search code examples
neo4jcypher

When to use a Property as opposed to a Label in Neo4j?


I am going over this YouTube tutorial, "Using LOAD CSV in the Real World".

The tutorial shows how to take a CSV, where each row is a complaint made against some bank, and model it as a Neo4j dictionary.

When doing so, the narrator sets Properties on the Complaint node:

CREATE (complaint:Complaint {id: line.`Complaint ID`})
SET complaint.year= TOINT(date[2]),
     complaint.month= TOINT(date[0]),
     complaint.day = TOINT(date[1])  

I'm confused about a small point -- what makes this date information more of a 'Property' than a Label?

Could this be modeled instead where the node has this information encapsulated as Labels instead of Properties? At what point do you need one of these and not the other?


Solution

  • Labels and properties are very different things.

    A property belongs to a node or a relationship, and has a name and a value.

    A node label is similar in concept to a "class name", and has no value.

    So, it does not make any sense to talk about putting a date value in a "label". You can only put a value in a property.

    Note, however, that people often use a label name (e.g., "Foo") as a shorthand for "node that has the Foo label". For example, they may say "store the date in Foo" when they actually mean "store the date in the appropriate property of a node with the label Foo". Perhaps this is what is causing the confusion.