运行参数化Neo4j密码查询 [英] Running parametrized neo4j cypher query

查看:136
本文介绍了运行参数化Neo4j密码查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下给出的密码查询将针对参数化列表中提到的每种关系类型重复进行,并且每种关系类型都有要添加到连接节点的特定属性和值.根据neo4j,无法参数化关系类型.反正有使用密码解决这个问题吗?或与apoc?

Given below is the cypher query which gets repeated for each relationship type as mentioned in parameterized list and each relationship type has specific property and value to be added to the connecting node. According the neo4j, it is not possible to parametrize relationship type. Is there anyway to address this using cypher? or with apoc?

Merge(n_device: Device{identifier: {deviceId}}) ON CREATE SET n_device.created=timestamp()
WITH n_device
OPTIONAL MATCH (n_device)-[r_prev:{deviceRel}{active:true}]->() 
WITH n_device, r_prev   
Merge(n_deviceOs: Device{{deviceRelProp}: {deviceRelPropVal}}) ON CREATE SET n_deviceOs :DeviceOs,  n_deviceOs.created=timestamp(), n_deviceOs.newNode=true
WITH n_device, n_deviceOs, r_prev
Merge (n_device)-[r_cur:{deviceRel}]->(n_deviceOs) ON CREATE SET r_cur.active=true, r_cur.created=timestamp()
WITH n_deviceOs, r_prev
Match(n_deviceOs) where n_deviceOs.newNode=true set r_prev.active = false, r_prev.modified=timestamp()
REMOVE n_deviceOs.newNode

"params": {
    "deviceId": "1234",
    "deviceRel": ["HAS_DEVICE_OS", "HAS_DEVICE_OSINFO", "HAS_DEVICE_MODEL", "HAS_DEVICE_APPVERSION"],
    "deviceRelProp": ["os", "osinfo", "model", "version"],
    "deviceRelPropVal": ["android", "kitkat", "samsung", "1.64.2"]
}

推荐答案

Neo4j无法使用参数化类型创建关系.但是有一个APOC程序可以做到这一点.请参见创建数据部分,apoc.create.relationship()为您正在寻找的过程.

Neo4j can't create a relationship with a parameterized type. But there is an APOC Procedure which allows this. See the creating data section, apoc.create.relationship() is the procedure you're looking for.

这篇关于运行参数化Neo4j密码查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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