尝试创建一个Cypher请求,该请求应创建(或合并)文件并创建与给定根文件夹的关系(可能尚未存在)。有一个单一约束:FILE(fullpath)和:FOLDER(fullpath)。 我写的代码看起来像这样:
async public void createFiles(File[] files, Folder rootFolder)
{
var query = client.Cypher
.Merge("(root:FOLDER {fullpath: {newRoot}.fullpath})")
.Merge("(file:FILE {fullpath : {newFiles}.fullpath})")
.Set("file = {newFiles}")
.CreateUnique("root -[:CONTAINS]->(file)")
.WithParam("newFiles", files)
.WithParam("newRoot", rootFolder)
.ReturnDistinct<int>("0");
await query.ResultsAsync;
}
但它会引发Neo4jClient.NeoException: ThisShouldNotHappenError: Developer: Andres claims that: Need something with properties
异常。
我认为第二个.Merge
引发了异常。是不是可以将多个节点与一个数组合并为参数?
这是一个错误还是我的嗅觉代码?
neo4j 2.1.3
答案 0 :(得分:3)
fadanner,
假设参数中存在所有底层部分,您可以通过将查询更改为此来执行所需操作:
var query = client.Cypher
.Merge("(root:FOLDER {fullpath : {newRoot}.fullpath})")
.ForEach("(newFile IN {newFiles} | MERGE (file:FILE {fullpath : newFile.fullpath}) SET file = newFile CREATE UNIQUE (root)-[:CONTAINS]->(file))")
.WithParam("newFiles", files)
.WithParam("newRoot", rootFolder)
.ReturnDistinct<int>("0");
我不是一个neo4jclient的人,所以我可能有一些语法错误,但这个等价物适用于REST(至少我认为它等效)。
:POST /db/data/cypher
{"query":"MERGE (n:Foo {name : {prop1}.name}) FOREACH(prop IN {prop2} | MERGE (m:Goo {name : prop.name}) SET m = prop CREATE UNIQUE (n)-[:HAS]->(m))", "params":{"prop1":{"name":"cat"},"prop2":[{"name":"boo","gleek":"math"},{"name":"oob","gleek":"spit"}]}}
恩典与和平,
吉姆