Chris Hall
Chris Hall

Reputation: 931

Py2neo - Correct usage of "set_node_property"

I'm trying to set a new property on a specific node within an indexed list using py2neo. The idea is the first node in the list will get a new property. The property value will be static so as to find all related nodes in the future. In the example below, the "nodez" list will change, however the first item always needs the new property and static value.

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)

So if the next time this program is run and nodez = ['test4', 'test5', 'test6'], then both 'test1' and 'test4' will contain the new property values. For example, the following cypher query would return the nodes for 'test1' and 'test4' in index "name". Thanks for any help!

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

Upvotes: 1

Views: 796

Answers (1)

Nigel Small
Nigel Small

Reputation: 4495

set_node_property is only applicable for batch operations. In this case, you simply need to use:

a[newpropkey] = newpropvalue

Upvotes: 2

Related Questions