如何使节点 属性 在 neo4j 中不可变?

How to make a node property immutable in neo4j?

我有一个 neo4j 数据库(社区版),我在其中设置了一个 属性 的唯一性约束,我称之为 'uid' 与标签 :USER 配对。

CREATE CONSTRAINT ON (user:USER) ASSERT user.uid IS UNIQUE

但是,我希望以一种在创建节点后无法对其进行任何更改但仍然能够更改其他属性的方式来保护此 属性。怎么能这样做呢?

根据Neo4j constraints documentations, has no way to do this out of the box. I believe that to achieve this goal you will need to make use of the Neo4j Java API and write a custom user defined procedure / function

查看 GraphAware Neo4j UUID library 以获取灵感。根据文档:

Neo4j UUID library is a simple library that transparently assigns a UUID to newly created nodes and relationships in the graph and makes sure nobody can (accidentally or intentionally) change or delete them.

您可以在 this source code.

上查看此要求的单元测试

据我所知目前在Neo4j中没有这样的东西。

有一个功能请求(https://github.com/neo4j/neo4j/issues/2554

您可以尝试通过编写自定义的用户定义过程或函数来强制执行不变性。