Reputation: 862
I am trying to build a cypher query that I plan to use as a json response to a http request. I’d like to have two keys in the json object: one key/property of type string and another key/property of type array that looks like this:
> {
> "id" : "9989898676876_all",
> "inventory" : [
> {
> "id" : "a_aaa",
> "isFavorite" : false
> }, {
> "id" : "b_bbb",
> "isFavorite" : false
> }, {
> "id" : "c_ccc",
> "isFavorite" : false
> }, {
> "id" : "d_ddd",
> "isFavorite" : false
> }
> ] }
I tried with this cypher query but cam up with errors:
MATCH n
WHERE n.id='9989898676876'
RETURN n.id + '_all' AS `id`
UNION
MATCH n-[inventory:ALL_]->leaf
WHERE n.id='9989898676876'
RETURN (leaf.id AS `id`, inventory.isFavorite AS `isFavorite`) AS `inventory`
Can someone please provide a fiddle example of a cypher response that concatenates a key/property of a string with a key/property of an array?
Upvotes: 0
Views: 65
Reputation: 66967
This is how you can get the results, with the inventory ordered by ascending leaf.id
:
MATCH n-[inventory:ALL_]->leaf
WHERE n.id='9989898676876'
WITH *
ORDER BY leaf.id
RETURN (n.id + '_all') AS id, COLLECT({ id: leaf.id, isFavorite: inventory.isFavorite }) AS inventory;
Upvotes: 2