Neo4j:无法创建具有嵌套属性的节点

时间:2018-09-24 20:20:56

标签: neo4j cypher

我到处搜索过,但是找不到答案。

我需要创建一个节点Config,该节点的动态属性对象具有2个键/值对(例如nametype)。查询键时,键应以properties.nameproperties.type结尾。但是我似乎无法正确使用create语法。这就是我正在做的:

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

但这给了我一些奇怪的错误:

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

有人可以帮我弄清楚这个查询吗?

2 个答案:

答案 0 :(得分:3)

Neo4j的property type集有限。

您应该将值存储为节点的属性,而不是将其添加到一个属性中。

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

如果这对您来说不够好,则需要将数据重新格式化为与Neo4j类型兼容的数据。

答案 1 :(得分:1)

创建嵌套属性的一种方法是使用JSON属性作为字符串属性,可以在写入时转储和编码数据,在读取时加载和解码。
其中一个示例是python中的neomodel json属性。

这是neomodel json属性的代码:

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)
相关问题