我必须在 Neo4j 中创建唯一的节点,但是这个查询不正确,因为 Neo4j 说
This pattern is not supported for CREATE UNIQUE
List<String> users = pUsers.collect();
for(String u : users){
if(u.equals("error"))
continue;
else{
String cql = " CREATE UNIQUE (n:User {value:'" + u +"'})";
st.executeUpdate(cql);
}
如何解决?
最佳答案
使用之前CREATE UNIQUE您需要MATCH
一个节点。之后,使用匹配的节点在图中创建唯一的模式。 CREATE UNIQUE
将在图表中进行最小的更改。我相信您需要的是MERGE
。 CREATE UNIQUE 文档说:
MERGE might be what you want to use instead of
CREATE UNIQUE
. Note however, thatMERGE
doesn’t give as strong guarantees for relationships being unique.
因此您可以调整代码以:
List<String> users = pUsers.collect();
for(String u : users){
if(u.equals("error"))
continue;
else{
String cql = "MERGE (n:User {value:'" + u +"'})";
st.executeUpdate(cql);
}
}
查看this answer .
关于java - Neo4j:在 JDBC 中不支持创建唯一的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136967/