I have a lot of nodes in my database that all have different properties. I don't know what properties a node exactly has because I automatically integrate the data. Because of my settings all properties of the nodes are stored as arrays. I'm looking for a way to convert the properties that only hold a single value into a string. Is there an easy way to do this?
I already have a solution for a propety that I know all nodes contain.
MATCH (n:BTOOntology) WHERE n.id IS NOT NULL UNWIND n.id as ID SET n.id=replace(ID,":","_");
However I don't want to do this for every property, so I'm looking for a more general solution where I can do this for all properties of one node especially since I don't know what properties a node has.
Thanks in advance!
Cheers, Jana
P.S. For those interested:
I integrate ontologies into a Neo4j graph database using neosemantics. Because I use the parameter
handleMultival: "ARRAY"
all property values of a node are stored as arrays.
Hi, yes I want to convert the property to a string if the array has one value.
The properties are in an array because I import data that can have more than one value for one property key. If I wouldn't store them in an array they would be overwritte during the import.
For example every node has the property label which can be something like label=[cell], but other nodes can have more than one value for the property label, e.g. label=[cancer, cancer cell].
I already found a solution. I use this command to return all property keys.
MATCH(n:BTOOntology) WITH KEYS(n) AS keys
UNWIND keys AS key
RETURN DISTINCT COLLECT(DISTINCT key);
Because I write a Python script with Py2neo I can then iterate through the list of keys and convert the array into a string when the array has the size 1.
MATCH(n:BTOOntology)
WHERE size(n.'+key+')=1
UNWIND n.'+key+' as PROP
SET n.'+key+' = PROP;
You will not be able to use the approach in your second query, as the 'size' method is only valid for strings and lists. You will get an error if passing a property of any other type. You don't know the properties that are lists?