Insert an array of objects as a property in neo4j

I am trying to insert an array of objects as a property in node. I tried

MERGE (ss:Label1 {sId: 12345})
  ON MATCH SET ss.id = 14770746012, ss.setC = 1,ss.nl = [{id: 24, status: 0}]
  ON CREATE SET ss.id = 14770746012, ss.setC = 1,ss.nl = [{id: 24, status: 0}]

If it starts, I get the following error:

Property values can only be of primitive types or arrays thereof

Whatever I tried with a nested array, it gave me the same error as above.

I studied in the Neo4j documentation that Neo4j cannot support "Nesting Property Values"

How to reach my requirement?

+4
source share
3 answers

Since Neo4j does not support hierarchical properties, one way to solve this problem is to create additional nodes:

MERGE (ss:Label1 {sId: 12345, id: 14770746012, setC: 1 })
MERGE (nl:Props:nlProp {id: 24, status: 0})
MERGE (ss)-[:hasProps]->(nl)
+3
source

stdob--, , ( , ..).

, , , , , , JSON:

MERGE (ss:Label1 {sId: 12345})
  ON MATCH SET ss.id = 14770746012, ss.setC = 1,ss.nl = ["{\"id\": 24, \"status\": 0}"]
  ON CREATE SET ss.id = 14770746012, ss.setC = 1,ss.nl = ["{\"id\": 24, \"status\": 0}"]
+2

Another option is to split the collection nlinto a separate collection for each item property. For instance:

MERGE (ss:Label1 {sId: 12345})
SET ss.id = 14770746012, ss.setC = 1, ss.nl_ids = [24], ss.nl_statuses: [0];

The corresponding values nl_idsand nl_statuseshave the same index.

In addition, because of your actions ON MATCH SET ..., and ON CREATE SET ...exactly the same, I just combined them into one sentence SET ....

0
source

Source: https://habr.com/ru/post/1658802/


All Articles