Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-21-2020 10:27 AM
I have some nodes in my db which have a label like this
"graph_information": [
"prova",
"password"
]
I want to change the values inside this array, but I can't to do it.
I tried in this way
MATCH (n)
WHERE
ANY(gi IN n.graph_information WHERE gi = 'prova')
set n.graph_information_new = ['prova2', n.graph_information[1] ]
remove n.graph_information
set n.graph_information = n.graph_information_new
remove n.graph_information_new
And it seems to work, but is there a better method to do this ?
Solved! Go to Solution.
04-21-2020 01:58 PM
Hi,
This is the test data.
CREATE (:SomeLabel {graph_information: ['prova', 'password']}),
(:SomeLabel {graph_information: ['prova', 'prova']}),
(:SomeLabel {graph_information: ['user1', 'prova']})
You can use ONE SET sentence like this.
But in your Where clause, I think the result is wrong.
MATCH (n)
WHERE
any(gi IN n.graph_information WHERE gi = 'prova')
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
n.graph_information
["prova2", "password"] <- OK
["prova2", "prova"] <- OK
["prova2", "prova"] <- The ID 'user1' has been changed.
I think 'prova' is an id, not a password, so it's better to specify it when searching.
MATCH (n)
WHERE n.graph_information[0] = 'prova'
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
["prova2", "password"] <- OK
["prova2", "prova"] <- OK
OR
MATCH (n)
WHERE n.graph_information = ['prova', 'password']
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
["prova2", "password"] <- OK
If you have a large number of records, you need an Index, so I think it's better to set the id and password as separate items from the array.
04-21-2020 01:58 PM
Hi,
This is the test data.
CREATE (:SomeLabel {graph_information: ['prova', 'password']}),
(:SomeLabel {graph_information: ['prova', 'prova']}),
(:SomeLabel {graph_information: ['user1', 'prova']})
You can use ONE SET sentence like this.
But in your Where clause, I think the result is wrong.
MATCH (n)
WHERE
any(gi IN n.graph_information WHERE gi = 'prova')
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
n.graph_information
["prova2", "password"] <- OK
["prova2", "prova"] <- OK
["prova2", "prova"] <- The ID 'user1' has been changed.
I think 'prova' is an id, not a password, so it's better to specify it when searching.
MATCH (n)
WHERE n.graph_information[0] = 'prova'
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
["prova2", "password"] <- OK
["prova2", "prova"] <- OK
OR
MATCH (n)
WHERE n.graph_information = ['prova', 'password']
SET n.graph_information = ['prova2', n.graph_information[1] ]
RETURN n.graph_information
["prova2", "password"] <- OK
If you have a large number of records, you need an Index, so I think it's better to set the id and password as separate items from the array.
All the sessions of the conference are now available online