Neo4j Cypher:在将一个节点替换为另一个节点之前,先转移所有关系 [英] Neo4j Cypher : transfer all relationships before replacing a node by another

查看:82
本文介绍了Neo4j Cypher:在将一个节点替换为另一个节点之前,先转移所有关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在删除第一个节点之前,我尝试将所有传入和传出关系从一个节点转移到另一个节点.他们都有相同的标签. 我看到了这个 Neo4j Cypher:复制关系并删除节点 但就我而言,我不知道这种关系的类型,我想转移传入和传出的关系.

I'm trying to transfert all ingoing and outgoing relationships from a node to another, before deleting the first one. they both have the same label. I saw this Neo4j Cypher: copy relationships and delete node but in my case i don't know the type of the relations and i want to transfer both ingoing and outgoing ones.

我正在寻找密码查询或基于neo4j.rb的查询

i'm looking for either a cypher query or a query based on neo4j.rb

推荐答案

我不认为使用纯密码可以做到这一点.这是一个我认为可以使用的使用neo4j.rb的解决方案:

I don't think that this is possible with pure cypher. Here's a solution using neo4j.rb that I think will work:

# Assuming node1 already loaded
node_query = Neo4j::Session.query.match(node: {neo_id: node1.neo_id})

types = node_query.match('node-[rel]-()').pluck('DISTINCT type(rel)')

types.each do |type|
  node_query.match('node-[rel]->(other)').with(:node, :rel, :other).create("node-[new_rel]->other").set('new_rel = rel').exec
  node_query.match('node<-[rel]-(other)').with(:node, :rel, :other).create("node<-[new_rel]-other").set('new_rel = rel').exec
end

这篇关于Neo4j Cypher:在将一个节点替换为另一个节点之前,先转移所有关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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