Cypher:如果节点不存在,则创建多个节点和关系

时间:2019-09-29 20:34:33

标签: neo4j cypher graph-databases cql

我要 (function localFileVideoPlayer() {'use strict' var URL = window.URL || window.webkitURL var displayMessage = function (message, isError) { var element = document.querySelector('#message') element.innerHTML = message element.className = isError ? 'error' : 'info' } var playSelectedFile = function (event) { var file = this.files[0] var type = file.type var videoNode = document.querySelector('video') var canPlay = videoNode.canPlayType(type) if (canPlay === '') canPlay = 'no' var isError = canPlay === 'no' if (isError) {return } var fileURL = URL.createObjectURL(file) videoNode.src = fileURL } var inputNode = document.querySelector('input') inputNode.addEventListener('change', playSelectedFile, false) })() 个节点:

MERGE

如果该节点不存在,我需要这样做:

MERGE (a: Article {URL: event.URL})

我认为ON CREATE FOREACH( site_name in CASE WHEN event.site_name is not null then [1] ELSE [] END | MERGE (w: Website { value: event.site_name}) MERGE (w)-[:PUBLISHED]->(a)) // all of the tag creation FOREACH( tag in CASE WHEN event.tags is not NULL then event.tags else [] END | Merge (t: Article_Tag {value: tag}) CREATE (a)-[: HAS_ARICLE_TAG {date:event_datetime}]->(t)) 仅适用于ON CREATE,但是如上所述,我需要执行多个语句。有没有一种方法可以使用SET子句创建多个节点和关系?

编辑:我已经尝试过ON CREATE,但这不能解决SET问题。

1 个答案:

答案 0 :(得分:0)

这是最好的方法:只需将其包装在FOREACH语句中

MATCH (a: Article {URL: event.URL})
FOREACH(ignoreme in case when a is not null then [1] else [] end |... Statement here...)