问题
I am new to neo4j and trying to add multiple values to a property of a node.How to do it?
create (e:Employee{name:"Sam",languages:["C","C#"]})
Tried this but didn't find any proper way to add multiple values to an attribute.
回答1:
Properties cannot have object values. If you're looking to store multiple properties on language
, and those properties all belong to the language and not any other entity, then you should model Language as a node. You can store properties on the relationship between the employee and language as well if required.
Then you'll end up with something like this:
create (l:Language {name:"C", otherProperty:"property value"})
create (e:Employee {name:"Sam"})
create (e)-[:SPEAKS {level:"Fluent"}]->(l)
回答2:
In fact, you can have array values in properties. You should be able to create them like:
CREATE (n:Node { color: ['Red', 'Blue']})
RETURN n
In your case:
CREATE (e:Employee { name:"Sam",languages: ["C", "C#"]})
RETURN e
is working perfectly fine (you can check it in http://console.neo4j.org/)
Keep in mind that all values in the array must be of the same type, only Strings, or Integers, etc. You can find more info here -> http://neo4j.com/docs/stable/rest-api-property-values.html
However that's not the best approach for that particular example given that C
and C#
are languages that Sam
knows, you should have them as different nodes pointed by Sam
through some kind of Knows
relationship.
来源:https://stackoverflow.com/questions/30842029/how-to-add-multiple-values-to-a-property-in-neo4j