Weird Neo4J Cypher behavior on setting relationship properties

白昼怎懂夜的黑 提交于 2020-01-16 16:11:11

问题


I have a Cypher request for Neo4J of this kind:

MATCH (u:User {uid: $userId}) 
UNWIND $contextNames as contextName 
MERGE (context:Context {name:contextName.name,by:u.uid,uid:contextName.uid}) 
ON CREATE SET context.timestamp=$timestamp 
MERGE (context)-[by:BY]->(u) 
SET by.timestamp = $timestamp 

My params are:

{
 "userId": "15229100-b20e-11e3-80d3-6150cb20a1b9",
 "contextNames": [
  {
    "uid": "822e2580-1f5e-11e9-9ed0-5b93e8900a78",
    "name": "fnas"
  }
 ],
 "timestamp": "1912811921129"
}

That query above sets 8 parameters because I have (probably) 8 other relationships of the :BY type in relation to that u. Which seems to me illogical as it should only find one relationship between a concrete context and a concrete u, create it if it doesn't exist, and set the property for it

However, when I do this:

 MATCH (u:User {uid: $userId}) 
 UNWIND $contextNames as contextName 
 MERGE (context:Context {name:contextName.name,by:u.uid,uid:contextName.uid}) 
 ON CREATE SET context.timestamp=$timestamp 
 MERGE (context)-[:BY{timestamp:$timestamp}]->(u)

It either creates a relationship (if the one with the same timestamp doesn't exist) or it simply doesn't do anything (which seems to be the right behavior).

What is the reason for this discrepancy? A bug in Neo4J?

来源:https://stackoverflow.com/questions/54337195/weird-neo4j-cypher-behavior-on-setting-relationship-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!