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.
What do you think should be the parameters for deciding between the options?
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.
Labels can also be used for grouping or tagging nodes, and also sometimes (depending on the use-case) for boolean or enumerated states. like
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!
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
where n:Ford for a boolean expression
All depends on the scope and mandate for the Db. Since a single driver can drive many cars (i.e. Manufacture) or a single car (i.e. Manufacture) can be driven by many drivers. It is safe to create separate nodes for both cars and divers and add properties where needed.
Moreover, in future, you might need to add more properties.