根据Neo4j中的特定条件创建节点 [英] create nodes depending on certain condition in Neo4j

查看:377
本文介绍了根据Neo4j中的特定条件创建节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要满足某些条件,我想在数据库中创建一些新节点

I want to create some new nodes in my database if some condition is satisfy

MATCH (u:User)-[:has]->(a:Account)-[:initiated]->(l:Process) WHERE ID(l)=984 
UNWIND [{mobile:123,email:'a@b.com'}, {mobile:456, email:'a1@b1.com'}] as x
OPTIONAL MATCH (u1:User) WHERE u1.mobile = x.mobile OR u1.email = x.email CASE u1 WHEN u1 IS NULL THEN CREATE (u)-[:pending]->(p:Pending {mobile: x.mobile, email: x.email})
ELSE CREATE (u1)-[:pending]->(p:Pending {mobile: x.mobile, email: x.email})
END 

我想检查是否存在使用手机或电子邮件的用户.如果存在,我想创建连接到该节点(u1)的节点(p),否则我想创建连接到我的节点即(u)的节点.

I want to check condition whether any users exist with mobile or email. If exist I want to create node (p) attached to there node (u1) else I want to create node attached to my node i.e (u).

以某种方式创建不起作用

Somehow create is not working in case

推荐答案

当前执行条件写入的唯一方法是使用FOREACH/CASE WHEN技巧.根据您的条件,您可以创建一个1元素或一个空数组,然后使用FOREACH对其进行迭代,例如

Currently the only way to do conditional writes is using the FOREACH/CASE WHEN trick. Based on your condition you create either a 1 element or an empty array and iterate over that using FOREACH, e.g.

...
FOREACH(x in CASE WHEN u1 IS null THEN [1] ELSE [] END | 
  CREATE (u)-[:pending]->(p:Pending {mobile: x.mobile, email: x.email}))
FOREACH(x in CASE WHEN u1 IS NOT null THEN [1] ELSE [] END | 
  CREATE (u1)-[:pending]->(p:Pending {mobile: x.mobile, email: x.email}))

请参见 http://www. markhneedham.com/blog/2014/06/17/neo4j-load-csv-handling-conditionals/了解更多详细信息.

See http://www.markhneedham.com/blog/2014/06/17/neo4j-load-csv-handling-conditionals/ for more details.

这篇关于根据Neo4j中的特定条件创建节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆