I want to assign a dictionary as node property value. When I try to assign it a dictionary it throws an error if cyphertype saying only arrays or primitive data types can be assigned. So the question is that is there any work around to this problem
There is no way to assign a dictionary as a single node property value.
But you can assign each key in the dictionary as a single property and save the dictionary that way.
WITH {params}
MATCH (n:Node)
SET n += params
Related
a=[1,2,3,4,5,6,7,8]
w=a.collect{|i| i%2==0}
p w
The result is coming to be
[false,true,false,true]
why?
When i am doing
w=a.collect{|i| i+2}
Result is an array like
[3,4,5,6,7,8,9,10,11]
Why? What am i doing wrong?
You don't need map / collect (they are aliases), you need
array.select(&:even?)
or
array.reject(&:odd?)
These methods filter original array, unlike map that performs actions with every element and returns new array of the same length
That's why you get boolean array same length instead of filtering
Please read more in docs:
Array#map, Array#select, Array#reject
I have the following situation:
I have an object
This object has an item that is an object again
The second object contains array of objects with ids
Can I filter only the parent objects that have subobjects that contain something in particular in the array on the bottom of the tree?
Try this:
$filter=nameOfObjectArrayProperty/any(o: contains(o/id, 'some-alue'))
or
$filter=nameOfObjectArrayProperty/any(o: o/id eq 'some-value')
It's also important to note that "/any" can be replaced with "/all" if you want all the subobjects to match your filter criteria.
I'm trying to set a property for a Node, with value as a json object. e.g., property: {jsonObject}. I cannot find any apoc procedure that could solve this problem
I tried using toJson, fromJsonMap etc apoc functions
WITH apoc.convert.fromJsonMap(jsonData) as v
MATCH (n:Node {property1: value})
SET n.property2 = v
RETURN n;
Neo.ClientError.Statement.TypeError: Property values can only be of primitive types or arrays thereof
As the error states, in neo4j a property value cannot be a map.
As cybersam says, you can't a map for a property value. However, if it's useful, you can represent them as an array - do bear in mind you'll need to manually format it as such, and retrieve.
I have nodes within a the graph with property pathway storing an array of of values ranging from
path:ko00030
path:ko00010
.
.
path:koXXXXX
As an example, (i'm going to post in the batch import format:https://github.com/jexp/batch-import/tree/20)
ko:string:koid name definition l:label pathway:string_array pathway.name:string_array
ko:K00001 E1.1.1.1, adh alcohol dehydrogenase [EC:1.1.1.1] ko path:ko00010|path:ko00071|path:ko00350|path:ko00625|path:ko00626|path:ko00641|path:ko00830
the subsequent nodes might have a different combination of pathway values.
How do i query using CYPHER to retrieve all nodes with path:ko00010 in pathway
the closest i've gotten is using the solution provided for a different problem:
How to check array property in neo4j?
match (n:ko)--cpd
Where has(n.pathway) and all ( m in n.pathway where m in ["path:ko00010"])
return n,cpd;
but here only nodes with pathways matching exactly to the list provided are returned.
ie. if i were to query path:ko00010 like in the example above, I'll only be able to retrieve nodes holding path:ko00010 as the only element in the pathway property and not nodes containing path:ko00010 as well as other path:koXXXXX
In your query the extension of the predicate ALL is all the values in the property array, meaning that your query will only return those cases where every value in the pathway property array are found in the literal array ["path:ko00010"]. If I understand you right you want the opposite, you want to test that all values in the literal array ["path:ko00010"] are found in the property array pathway. If that's indeed what you want you can just switch their places, your WHERE clause will then be
WHERE HAS(n.pathway) AND ALL (m IN ["path:ko00010"] WHERE m IN n.pathway)
It is not strictly correct to say that your query only matches cases where the array you ask for and the property array are exactly the same. You could have had more than one value in the literal array, something like ["path:ko00010","path:ko00020"], and nodes with only one one of those values in their pathway array would also have matched–as long as all values in the property array could be found in the literal array. Conversely, with the altered WHERE filter that I've suggested, the query will match any node that has all of the values of the literal array in their pathway property.
If you want to filter the matched patterns with an array of values where all of them have to be present, this is good. In your example you only use one value, however, and for those queries there is no reason to use an array and the ALL predicate. You can simply do
WHERE HAS(n.pathway) and "path:ko00010" IN n.pathway
If in some context you want to include results where any of a set of values are found in the pathway property array you can just switch from ALL to ANY
WHERE HAS(n.pathway) AND ANY (m IN ["path:ko00010","path:ko00020"] WHERE m IN n.pathway)
Also, you probably don't need to check for the presence of the pathway property, unless you have some special use for it you should be fine without the HAS(n.pathway).
And once you've got the queries working right, try to switch out literal strings and arrays for parameters!
WHERE {value} IN n.pathway
// or
WHERE ALL (m IN {value_array} WHERE m IN n.pathway)
// or
WHERE ANY (m IN {value_array} WHERE m IN n.pathway)
Is there an easy way to sort an array of custom objects (in this case Lists) into a dictionary based on a particular property of each list.
[List1, List2, List3, List4, List5];
For example, each List object has an NSString type property, which can be either "MyList","Sent","Received"
How would I create a dictionary based on these properties so that I have a dictionary like so:
"MyList" -> array of lists with MyList as their type property [List1, List5];
"Sent" -> array of lists with Sent as their type property "Received" [List3;
"Received" -> array of lists with Received as their type property [List2, List4];
I'd really rather not loopthrough my entire array of List objects if possible
You need to iterate the array and build your dictionary. If the key isn't already there, create the array and add it to the dictionary, then add the new item to it.
You could alternately use predicates to filter the array into sub-arrays and build the dictionary like that but it's a similar amount of code (for a few options) and doesn't support automatic future expansion when you have another value for the key you're organising on.