O'Reilly logo

Learning Neo4j 3.x - Second Edition by Rik Van Bruggen, Jérôme Baton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Merging nodes 

It is possible to merge several nodes together. Let's create some nodes:

CREATE (a:FIRST:MERGE {propF1: 'AF1',propF2: 'AF2'}), (b:SECOND:MERGE {propS1: 'BS1',propS2: 'BS2'}), (c:THIRD:MERGE {propT1: 'CT1',propT2: 'CT2',propT3: 'CT3'})

Now let's see them:

MATCH (n:MERGE)RETURN n

All right. Now, let's merge them onto the first node with this query:

MATCH (a:FIRST:MERGE), (b:SECOND:MERGE), (c:THIRD:MERGE)CALL apoc.refactor.mergeNodes([a,b,c]) YIELD node RETURN node

This results in a single node with four labels and the following properties (this is a copy/paste from the text view):

{"propF2":"AF2","propF1":"AF1","propS1":"BS1","propT2":"CT2","propT1":"CT1","propS2":"BS2","propT3":"CT3"}

This was the expected result. Now what if ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required