Last active
April 1, 2022 01:52
-
-
Save clemp/bbe87f4a877d011316155fa0ce454098 to your computer and use it in GitHub Desktop.
Merge Neo4j nodes on a property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create nodes. | |
merge (w1:Wallet {address: "0xc75446a6adaef73269dbdece73536977b2b639e0"}) // all lowercase | |
merge (w2:Wallet {address: "0xC75446A6AdaEF73269dBdEcE73536977B2b639e0"}) // mixed case | |
merge (w3:Wallet {address: "0x97b9958facec9acb7adb2bb72a70172cb5a0ea7c"}) // all lowercase | |
merge (w4:Wallet {address: "0x97b9958faceC9ACB7ADb2Bb72a70172CB5a0Ea7C"}) // mixed case | |
merge (w5:Wallet {address: "0x6989bEB3Fc8842704F05139ba2ED2b1182B3BaC9"}) // mixed case | |
// Match nodes with same address | |
MATCH (w:Wallet) | |
WITH w ORDER BY w.address DESC // lowercase one first | |
WITH toLower(w.address) AS address, collect(w) as nodes | |
CALL apoc.refactor.mergeNodes(nodes, {properties: { | |
address:'discard', mergeRels:true // 'discard' means keep the property from the first matched record, drop the rest | |
}}) | |
YIELD node | |
RETURN node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment