Wednesday, April 19, 2017

How to merge duplicate entries in Neo4J?

I needed to create a unique index on the "User"'s property "login". So I created a constraint on user.login.

CREATE CONSTRAINT ON (user:User) ASSERT user.login IS UNIQUE

The graph db already had duplicate entries for user login, so I need to remove or merge duplicate entries into one record.

This functionality is not possible by default by Cypher but we can do it by plugin  "Apoc", as follow

MATCH (n:User) with n.login as login , collect(n) as nodelist, count(*) as count where count > 1 call apoc.refactor.mergeNodes(nodelist) yield node return node;

No comments:

The Y Combinator (Slight Return)

Tiger got to hunt, Bird got to fly; Lisper got to sit and wonder, (Y (Y Y))? Tiger got to sleep, Bird got to land; Lisper got to tell hims...