دنبال کننده ها

۱۳۹۶ مرداد ۱۰, سه‌شنبه

neo4j - Modifying cypher query

[ad_1]



I have neo4j data as like as given below:



enter image description here



Here I have COUNTEY_PROVINCE relationship between country and province, PROVINCE_CITY relationship between province and city and COUNTRY_CITY relationship between country and city. When user call an api with country name, I want to return all province with city. To do this, I have run the following query:



 MATCH path=(cn:Country name: "Bangladesh" )-[:COUNTRY_PROVINCE]->(pv:Province)-[:PROVINCE_CITY]->(ct:City)
RETURN x: nodes(path)


And I have got the following result ( country, province, city ) :



 x: nodes(path) 
"x": [ "name": "Bangladesh", "name": "Dhaka" , "name": "Dhaka" ]
"x": [ "name": "Bangladesh", "name": "Dhaka" , "name": "Narayanganj" ]
"x": [ "name": "Bangladesh", "name": "Sylhet" , "name": "Sylhet" ]
"x": [ "name": "Bangladesh", "name": "Khulna" , "name": "Khulna" ]
"x": [ "name": "Bangladesh", "name": "Khulna" , "name": "Jessore" ]
"x": [ "name": "Bangladesh", "name": "Chittagong" , "name": "Chittagong" ]
"x": [ "name": "Bangladesh", "name": "Chittagong" , "name": "Comilla" ]


Now my question is, how can I get country list with province and associate cities like :



 [

country:
name: "Bangladesh",
province: [

name: "Dhaka",
city: [
name: "Dhaka" ,
name: "Narayanganj"
]
,

name: "Sylhet",
city: [
name: "Sylhet"
]
,

name: "Chittagong",
city: [
name: "Chittagong" ,
name: "Comilla"
]
,

name: "Khulna",
city: [
name: "Khulna" ,
name: "Jessore"
]

]


]



[ad_2]

لینک منبع