1

我正在尝试使用 py2neo 在索引列表中的特定节点上设置新属性。这个想法是列表中的第一个节点将获得一个新属性。属性值将是静态的,以便将来查找所有相关节点。在下面的示例中,“nodez”列表将发生变化,但第一项始终需要新属性和静态值。

from py2neo import neo4j, cypher
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

nodez = ['test1', 'test2', 'test3']
mytestindex = graph_db.get_or_create_index(neo4j.Node, "name")
nodes2 = []
for word in nodez:
    nodes2.append(mytestindex.get_or_create("name", word, {"name": word}))
a = nodes2[0]
newpropkey = "new_property"
newpropvalue = "static_value"
set_node_property(a, newpropkey, newpropvalue)

所以如果下次运行这个程序并且 nodez = ['test4', 'test5', 'test6'],那么 'test1' 和 'test4' 都将包含新的属性值。例如,以下密码查询将返回索引“name”中“test1”和“test4”的节点。谢谢你的帮助!

START a = node:name(new_property="static_value")
4

1 回答 1

2

set_node_property仅适用于批处理操作。在这种情况下,您只需要使用:

a[newpropkey] = newpropvalue
于 2013-02-03T09:36:20.593 回答