Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Maps and Collections in Neo4j 2

Tags:

neo4j

cypher

I understand that node and relationship properties are limited to primitive types or arrays of primitive types. The "Maps" section of the Neo4j 2.1 Reference Card mentions that:

{name:'Alice', age:38, address:{city:'London', residential:true}}

Literal maps are declared in curly braces much like property maps. Nested maps and collections are supported.

Of course something like:

CREATE (alice {name:'Alice', age:38, address:{city:'London', residential:true}})

throws an exception:

Error: Property values can only be of primitive types or arrays thereof Neo.ClientError.Statement.InvalidType

In what context does Neo4j support nested maps and collections?

like image 315
condit Avatar asked Sep 09 '14 16:09

condit


People also ask

Does Neo4j support nested arrays in a record?

Neo4j does not allow nested arrays to be stored as properties of a node.

How do I add multiple nodes in Neo4j?

The create clause of Neo4j CQL is also used to create multiple nodes at the same time. To do so, you need to pass the names of the nodes to be created, separated by a comma.

Can a node have multiple labels Neo4j?

Neo4j CQL CREATE a Node Label We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node. That means Neo4j supports only single Relationship Type between two nodes.

What is unwind in Neo4j?

With UNWIND , you can transform any list back into individual rows.


1 Answers

(Edited)

The reference card is a bit too subtle. The most important word is "literal". In other words, you can only use arbitrarily nested maps and arrays in literals, but you cannot store such things in a node or relationship.

For example, this works:

WITH {name:'Alice', age:38, address:[{city:'London', residential:true}, {city: 'Paris', residential: false} ]} AS x
RETURN x;

But this fails:

CREATE (x {name:'Alice', age:38, address:[{city:'London', residential:true}, {city: 'Paris', residential: false} ]})
RETURN x;
like image 135
cybersam Avatar answered Oct 13 '22 16:10

cybersam