cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

replacing an item in a list with a new one. the list is a property in a node

(class:CLASS {names: ['sam','John',amal','greg','sam','nabil','greg',John',sam'])

in my graph, I have a node called class. one of its properties is a list property called names.

I am trying to traverse all nodes of class and replace all occurrences of a word with another new word. the name list might have one or more occurrences of the same word.

need your help 🙂

4 REPLIES 4

Do you have a specific mapping of the existing values to the new values? Do you want to remove the duplicates?

you should use some of the functions in the apoc collections group to simplify your tasks.

https://neo4j.com/labs/apoc/4.4/overview/#_apoc_coll

I can help with a specific query if you answer the questions and provide the mappings.

Thank you

the problem is simple but I am stuck

I am in data cleansing phase

there will be an input list “inList” of strings (unique items and no duplicates), I need to search this inList string against a property called “names” in every CLASS node. Whenever a match of any item in the inList with any item in names, the item in names should be replaced with two items which are the first letter and the rest of the item.

inList[“Ali”, “Sam”,”Ali”]
(node:CLASS {names:[“Sam”,”Nour”,”Danny”,”Ali”, “Sally”, “Ali”]})

the outcome after update should look like:

node:CLASS {names:[“S”,”am”,”Nour”,”Danny”,”A”,”li”, “Sally”, “A”,”li”]})
the number two f nodes is more than 14,000

the names list is variable in length and the

You stated the inList will not include duplicates, but your example does. I assume that is an error. Does the solution need to retain the original order of the names list?

you are right, I made a mistake in inList. it should not have duplicates. and yes, the solution should retain the original order in the list. just replace the found item with its first character and the rest of the item.