Label Vs. Property, what should I choose?

(Michael Weston) #1


I need help understanding what should be considered when deciding whether to use a property or a label for some information about a node.

For example: If I have a node representing a car, and I want to insert the manufacturer (company) name, and whether it's an electric car or not.


Label: Ford
Property: manufacturer_name="Ford"

Label: electric
Property: is_electric="True"

What do you think should be the parameters for deciding between the options?


(Stefan Armbruster) #2

Use a label if you need to quickly iterate over all Ford cars or all electric cars. Also labels are a good choice if you e.g. want to apply a unique constraints on all ford cars.
Be aware that writing a label is more expensive than writing a property.

In contrast: if you just need it when assembling the return for a query, you might be better off with properties.

(Michael Hunger) #3

Labels can also be used for grouping or tagging nodes, and also sometimes (depending on the use-case) for boolean or enumerated states. like :Active.

(Michael Weston) #4

Thank you very much for your replies!

What about the following Label disadventage:
Let's assume we have a graph consisting of car nodes and driver nodes.
the car nodes have a manufacturer-name label, e.g. "FORD".

Now, the question is: If I have a driver-id, and I want to fetch the manufacturer-name of the car he drives, it appears that what I will do is:
I would select the driver node from the graph, and then get the car node (in which he drives), but then - how can I get the "FORD" label as a string? (Assuming I don't know it's a Ford, and it might be 100 other company names).

If it's not possible, is it correct to say that in such case (where I need to be able to do that) the manufacturer-name should be a property?

Thanks a lot!

(Michael Hunger) #5

Yes it should be a property there (or depending on use-case a related node).

Esp. if you have more than a few (let's say 3) states for a label then it becomes more tricky.

You can use something like this:

head([company IN $companies where company IN labels(node)])

to find out which label a node has dynamically in cypher

otherwise where n:Ford for a boolean expression