我想以这种方式将多组参数作为某种数组传递给Neo4j查询:
:params
"nodes": [
{
"id": 193331567,
"lat": 40.7599983215332,
"lon": -73.98999786376953
},
{
"id": 107475182,
"lat": 41.88999938964844,
"lon": -87.62000274658203
},
{
"id": 66276172,
"lat": 40.72999954223633,
"lon": -74.01000213623047
},
{
"id": 154076092,
"lat": 37.779998779296875,
"lon": -122.41999816894531
}
]
{
我有一个参数为id,lat,lon的查询。如何使用我设置的这个节点属性在一个查询中传递每组参数?
查询类型:
MATCH (m:Member)-[mtg_r:MT_TO_MEMBER]->(mt:MemberTopics)-[mtt_r:MT_TO_TOPIC]->(t:Topic),
(t1:Topic)-[tt_r:GT_TO_TOPIC]->(gt:GroupTopics)-[tg_r:GT_TO_GROUP]->(g:Group)-[h_r:HAS]->
(e:Event)-[a_r:AT]->(v:Venue) WHERE mt.topic_id = gt.topic_id AND distance(point({ longitude:
{lon}, latitude: {lat}}),point({ longitude: v.lon, latitude: v.lat })) < 4000 AND
mt.member_id = {id} RETURN distinct {id} as member_id, {lat} as member_lat,
{lon} as member_lon, g.group_name as group_name, e.event_name as event_name, v.venue_name
as venue_name, v.lat as venue_lat, v.lon as venue_lon, distance(point({ longitude: {lon},
latitude: {lat}}),point({ longitude: v.lon, latitude: v.lat })) as distance
答案 0 :(得分:1)
如果您的目标是遍历节点,则可以这样做:
创建节点参数
:param nodes => [ {id:193331567, lat:40.7599983215332,lon:-73.98999786376953 }, {id:107475182, lat:41.88999938964844,lon:-87.62000274658203 }]
使用此查询在您的节点上执行UNWIND
(即循环)
WITH $nodes as nodes
UNWIND nodes AS node
with node.id AS id, node.lon AS lon, node.lat AS lat
MATCH
(m:Member)-[mtg_r:MT_TO_MEMBER]->(mt:MemberTopics)-[mtt_r:MT_TO_TOPIC]->(t:Topic),
(t1:Topic)-[tt_r:GT_TO_TOPIC]->(gt:GroupTopics)-[tg_r:GT_TO_GROUP]->(g:Group)-[h_r:HAS]->
(e:Event)-[a_r:AT]->(v:Venue)
WHERE mt.topic_id = gt.topic_id AND
distance(point({ longitude: lon, latitude: {lat}}),point({ longitude: v.lon, latitude: v.lat })) < 4000 AND
mt.member_id = id
RETURN
distinct id as member_id,
{lat} as member_lat,
lon as member_lon,
g.group_name as group_name,
e.event_name as event_name,
v.venue_name as venue_name,
v.lat as venue_lat,
v.lon as venue_lon,
distance(point({ longitude: lon, latitude: {lat}}),
point({ longitude: v.lon, latitude: v.lat })) as distance
但是在这种情况下,您需要通过仅用查询变量替换查询参数来更改查询。