Reputation: 12034
I'm trying store a dynamic json array in a node, using Neo4J
.
MATCH (n:Users)
WHERE n.email = '[email protected]'
SET n.rated = [{email: '[email protected]', date: '09/11/2015'},
{email: '[email protected]', date: '09/11/2015'}]
RETURN n
Also, reading the post: Cypher query JSON formated result I'm just trying with:
MATCH (n:Users)
WHERE n.email = '[email protected]'
SET n.rated = [['[email protected]','09/11/2015'],
['[email protected]','09/11/2015']]
RETURN n
But I'm getting the error: Collections containing mixed types can not be stored in properties.
Is possible set a json result or an array in node property?
Upvotes: 2
Views: 2065
Reputation: 71026
You cannot have nested complex data within a node. In your case, you're trying to store a nested array of documents, then attempting an array of arrays. You may only have arrays of primitive types (e.g. an array of string, or an array of integer).
EDIT Just adding this, as there seems to be some confusion around using a graph database (specifically, Neo4j). To deal with the type of nested data you're trying to store in an array, you can simply store each of those nested objects as its own node, with a relationship back to the original node (e.g.[:RATED]
). This would allow you to have your entire list of properties (email, date) on each additional node, and you'd then be able to query this data as you would be able to query any data in the root node of your example.
Upvotes: 4
Reputation: 1893
As @david-makogon states, this cannot be done. I won't repeat his answer here.
I have achieved this previously by storing the JSON as a string.
MATCH (n:Users)
WHERE n.email = '[email protected]'
SET n.rated = "[{email: '[email protected]', date: '09/11/2015'},
{email: '[email protected]', date: '09/11/2015'}]"
RETURN n
This will store the result you want but may require some manipulation when you retrieve it. This may or may not match your requirement.
I have used this approach using serialiazation/deserialization as necessary.
Upvotes: 1