简体   繁体   English

Java与Neo4j Cypher

[英]Java with Neo4j Cypher

I want to create a relationship between a certain node (user) to all other nodes (items) with id in a list parameter : 我想在list参数中使用id创建特定节点(用户)与所有其他节点(项目)之间的关系:
i wrote this query : 我写了这个查询:

"FOREACH(it in {h_items} | "
" MATCH (u:User),(i:Item)"
" WHERE u.username = "+username+" AND i.itemId = it"
" CREATE (u)-[h:HAVE_HOBBY]->(i)"
" RETURN r

which should create a relationshipt between user with "username" to item that have itemId = it. 这应该在具有“用户名”的用户与具有itemId = it的项目之间建立关联。
it should be iterator on a list of items that i give to : 它应该是我给的项目列表上的迭代器:

ArrayList<String> hobby_items = new ArrayList<String>();
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("h_items", hobby_items);
execute(query,param);  

this gives the error : 这给出了错误:

Invalid use of MATCH inside FOREACH 在FOREACH中无效使用了MATCH

as it turned out that match inside foreach isn't allowed . 事实证明,在foreach内部不允许比赛。
what is the write way to write this query ? 编写此查询的写方式是什么?

This may work for you: 这可能对您有用:

MATCH (u:User)
WHERE u.username = { username }
UNWIND { h_items } AS it
MATCH (i:Item)
WHERE i.itemId = it
CREATE (u)-[:HAVE_HOBBY]->(i)
RETURN u, i;

You would provide {username} and {h_items} as parameters. 您将提供{username}{h_items}作为参数。 Your query returned r , which is not defined, so this query returns u and i . 您的查询返回了r (未定义),因此该查询返回ui

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM