我创建了以下查询,当我传递所有关系时它工作正常。
@Query(value="START profile=node(*) "
+ "MATCH profile - [rel:create | stream | like | follow] - feeds "
+ "WHERE profile.id ={profileId} "
+ "WITH distinct feeds as feed, rel.date as date "
+ "ORDER BY date DESC "
+ "RETURN DISTINCT feed;")
public List<Feed> findByProfileId(@Param("profileId") String profileId);
但我想为特定操作获取数据,例如下面的查询
@Query(value="START profile=node(*) "
+ "MATCH profile - [rel:{action}] - feeds "
+ "WHERE profile.id ={profileId} "
+ "WITH distinct feeds as feed, rel.date as date "
+ "ORDER BY date DESC "
+ "RETURN DISTINCT feed;")
public List<Feed> findByProfileId(@Param("action") String action,@Param("profileId") String profileId);
但这不起作用,我收到以下错误。
org.neo4j.rest.graphdb.RestResult Exception: Invalid input '{': expected whitespace or an identifier
我认为这不是在关系中传递参数的正确方法。 有什么方法可以实现这一点。
最佳答案
您不应该在查询中使用
上的索引/唯一约束start n=node(*)
使用像:Profile
这样的标签和:Profile(id)
MATCH (profile:Profile) WHERE profile.id = {profileId}
您不能直接使用 rel-types 作为参数,但您可以检查关系的类型,例如针对传入的一组名称
要么
WHERE type(rel) = {action}
或
WHERE type(rel) IN {actions}
关于java - Neo4j : Passing Relationship as a query parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27690099/