Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Neo4jClient删除关系_Neo4j_Neo4jclient - Fatal编程技术网

如何使用Neo4jClient删除关系

如何使用Neo4jClient删除关系,neo4j,neo4jclient,Neo4j,Neo4jclient,在继续使用neo4j之前,我正在努力掌握基本知识。喜欢查询方面,但现在尝试使用neo4jclient删除并卡住 简单设置 root-[:has_user]->user 及 用户-[:朋友与]->朋友` 对于Id为1的用户,我希望从Id==2删除指定的。用户1不再是用户2的朋友:( 无论如何,使用neo4jclient,我首先检查以确保用户首先是朋友: if (client.Cypher.Start("root", client.RootNode) .Match("root-[:HAS_U

在继续使用neo4j之前,我正在努力掌握基本知识。喜欢查询方面,但现在尝试使用neo4jclient删除并卡住

简单设置
root-[:has_user]->user 及 用户-[:朋友与]->朋友`

对于Id为1的用户,我希望从Id==2删除指定的。用户1不再是用户2的朋友:(

无论如何,使用neo4jclient,我首先检查以确保用户首先是朋友:

if (client.Cypher.Start("root", client.RootNode)
    .Match("root-[:HAS_USER]->user-[:FRIEND]->friend")
    .Where((UserNode user, UserNode friend) => user.Id == 1 && friend.Id == id)
    .Return<Node<UserNode>>("user")
    .Results
    .Count() == 1)
{
没有错误,但关系仍然存在。有什么想法吗

2012年12月11日更新

让它工作起来。我首先用稳定的1.8更新了Neo4J实例。我认为最新的neo4jclient和Neo4J服务器不能一起工作。我首先根据id获取用户的节点,然后从该节点测试节点是否有关系,然后能够删除它。代码如下:

        var currentUserNode = client.Cypher.Start("root", client.RootNode)
            .Match("root-[:HAS_USER]->user")
            .Where((UserNode user) => user.Id == 1)
            .Return<Node<UserNode>>("user")
            .Results.Single();

        if (currentUserNode.StartCypher("user")
                .Match("user-[r]->friend")
                .Where("friend.Id = " + id).And()
                .Where("type(r) = 'FRIEND'")
            .Return<Node<UserNode>>("user")
            .Results
            .Count() == 1)
        {

            currentUserNode.StartCypher("user")
                .Match("user-[r]->friend")
                .Where("friend.Id = " + id).And()
                .Where("type(r) = 'FRIEND'")
                .Delete("r").ExecuteWithoutResults();
        }
var currentUserNode=client.Cypher.Start(“root”,client.RootNode)
.Match(“根-[:HAS_USER]->USER”)
.Where((UserNode user)=>user.Id==1)
.Return(“用户”)
.Results.Single();
if(currentUserNode.StartCypher(“用户”)
.Match(“用户-[r]->friend”)
.Where(“friend.Id=“+Id”)。和()
其中(“类型(r)=‘朋友’”)
.Return(“用户”)
.结果
.Count()=1)
{
currentUserNode.StartCypher(“用户”)
.Match(“用户-[r]->friend”)
.Where(“friend.Id=“+Id”)。和()
其中(“类型(r)=‘朋友’”)
.Delete(“r”).ExecuteWithoutResults();
}

一种方法是切换到使用CypherFluentQuery:

new CypherFluentQuery(client)
    .Start("root", client.RootNode)
    .Match("root-[:HAS_USER]->user-[r]->friend")
    .Where("user.Val = 1").And()
    .Where("friend.Val = " + 2).And()
    .Where("type(r) = 'FRIEND'")
    .Delete("r").ExecuteWithoutResults();
你想怎么做就怎么做

我相信这一切都源于一个bug:

至于为什么
client.Cypher.Start
不能正常工作,我不确定该bug是否已修复,应该从1.0.0.479版开始工作(撰写本文时的当前版本是1.0.0.496)

  • 使用1.0.0.500之后的任何Neo4jClient构建。看看您是否对原因感兴趣
  • 别忘了调用
    ExecuteWithoutResults
    。问题中的第一个代码示例缺少此代码。这在上有说明

  • 如果您在控制台中运行纯密码查询,它能工作吗?好主意,ulkas,我将尝试使用最新版本496。尝试将ExecuteWithoutResults添加到我的现有代码和CypherFluentQuery中,我得到以下结果:在执行请求时收到意外的HTTP状态。查询为:START root=node({p0})匹配根-[:HAS_USER]->USER-[r]->friend WHERE(USER.Id=1)和(friend.Id=2)和(type(r)='friend')DELETE r响应状态为:400错误请求原始响应正文为:{“message”:“expected return子句”\n\“DELETE r\”\n^,“exception”:“expected return子句”\n\“DELETE r\”\n^”,我运行的是1.6.1,更新为1.9.M01,现在得到:“消息”:“找不到密钥:用户”.好的,我使用的是1.8,1.9是非生产版本,当我切换到1.9.M01 db时,我也会出现错误。据我所知-neo4jclient目前支持1.8…这不是一个很好的答案,但我认为使用1.8会给你最好的机会…我在控制台出现错误,所以看起来neo4j有点变化或什么?我是能够将where放在匹配的末尾,但不能放在匹配的“用户”部分。我将返回到1.8。尝试将“cypher 1.8”前缀放在命令中,并在控制台中再次运行它。我也必须多次这样做,才能真正迫使cypher使用支持许多语法功能的1.8版本
    new CypherFluentQuery(client)
        .Start("root", client.RootNode)
        .Match("root-[:HAS_USER]->user-[r]->friend")
        .Where("user.Val = 1").And()
        .Where("friend.Val = " + 2).And()
        .Where("type(r) = 'FRIEND'")
        .Delete("r").ExecuteWithoutResults();