1
votes

I have searched everywhere, but cannot find the answer to this.

I need to create a node Config that has a dynamic properties object with 2 key/value pairs (for example, name and type). The keys, when queried, should end up as properties.name and properties.type. But I cannot seem to get the create syntax right. This is what I'm doing:

CREATE (c1:Config) set c1.properties=[{name:"CiPipelineConfig1"}, {type:"test"}]

But that gives me some weird error:

Neo.ClientError.Statement.TypeError: Neo4j only supports a subset of Cypher types for storage as singleton or array properties.

Can anyone help me figure this query out?

2

2 Answers

3
votes

Neo4j has a limited property type set.

You should store the values as properties of the node, instead of craming them into one property.

// You need the `` around the property name to escape the period
CREATE (c1:Config) set c1.`properties.name`="CiPipelineConfig1" set c1.`properties.type`="test"

If this is not good enough for you, you will need to reformat your data to something that is compatible with the Neo4j Types.

2
votes

One way to create nested properties is using JSON property as string property, you can dump and encode data in write and load and decode when read.
One example of this is neomodel json property in python.

This is code of neomodel json property:

class JSONProperty(Property):
    """
    Store a data structure as a JSON string.

    The structure will be inflated when a node is retrieved.
    """
    def __init__(self, *args, **kwargs):
        super(JSONProperty, self).__init__(*args, **kwargs)

    @validator
    def inflate(self, value):
        return json.loads(value)

    @validator
    def deflate(self, value):
        return json.dumps(value)