Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

rest - Create is working but MERGE in neo4j post params has error

I have the code below .And a I am getting this error.How can I fix it ?

BTW CREATE for the same is working:

 <?php

$data2='{
  "names" : [{
    "name" : "Keanu Reeves1",
    "role" : "Neo1"
  },
  {
    "name" : "Keanu Reeves2",
    "role" : "Neo2"
  },
  {
    "name" : "Keanu Reeves3",
    "role" : "Neo3"
  }]
}';


$data ='MERGE (u:Person {names}) RETURN u';


$data2=json_decode($data2);


$data = array("query" =>$data,"params"=>$data2 );
$data_string = json_encode($data);


print_r($data_string);
//print_r($data2);
$ch = curl_init('http://192.....:7474/db/data/cypher');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
);

print_r ($ch);

$result = curl_exec($ch);

print_r($result);

?>

Error:

Parameter maps cannot be used in MERGE patterns

{ "message" : "Parameter maps cannot be used in MERGE patterns (use a literal map instead, eg. "{id: {param}.id}") (line 1, column 17)
"MERGE (u:Person {names}) RETURN u"
 ^", "exception" : "SyntaxException", "fullname" : "org.neo4j.cypher.SyntaxException"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately due to reasons for query planning those maps cannot be used in merge. Same as if you would have dynamic table columns in sql.

what you can do though is:

create constraint on (n:Label) assert n.id is unique;

MERGE (n:Label {id:{map}.id})
ON CREATE SET n={map}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...