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
Neo4j 根据条件,创建节点并返回值_Neo4j_Neo4jclient - Fatal编程技术网

Neo4j 根据条件,创建节点并返回值

Neo4j 根据条件,创建节点并返回值,neo4j,neo4jclient,Neo4j,Neo4jclient,在我的neo4j数据库中,我有两种节点类型: public class Warrior { public string Id{get;set} public string Name{get;set;} } public class Weapon { public string Id{get;set;} public string Name{get;set;} } 我希望我的查询具有如下相同的功能: var warrior = Match(warrior.Id

在我的neo4j数据库中,我有两种节点类型:

public class Warrior
{
    public string Id{get;set}
    public string Name{get;set;}
}

public class Weapon
{
    public string Id{get;set;}
    public string Name{get;set;}
}
我希望我的查询具有如下相同的功能:

var warrior = Match(warrior.Id == 1)
var weapon = Match(weapon.Id == 2)

if (warrior == null)
    return 0;

if (weapon == null)
    return 1;

CreateConnection(warrior-[:HAS]->Weapon)
return 2;
多谢各位


p/S:Neo4j或Neo4jClient查询被接受,我可以将它们相互转换。

以下查询应满足您的要求

optional match (warrior:Warrior) where warrior.id=1 with warrior
optional match (weapon:Weapon) where weapon.id=2 with warrior,weapon,
case when exists(warrior.id) and exists(weapon.id) then 2 when exists(weapon.id) then 1 else 0 end as output
foreach(temp in case when output=2 then [1] else [] end | 
    create (warrior)-[:Has]->(weapon)
)
return warrior,weapon
我们使用可选的match而不是match,以便在匹配未成功时查询不会失败

我们使用case语句检查warrior或armor变量的ID值是否存在,并将结果值(0、1或2)存储在输出变量中

接下来,我们使用foreach循环case技巧检查输出值是否为2,并执行create语句


(技巧参考。)

因为我不想每次创建连接时都检查用户或武器是否存在。我只是将信息发送到graph db,然后根据收到的结果,告诉客户他们需要解决的问题