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:

Finite-State Machines, Part 1: Modeling with Haskell Data Types

Stateful programs often become complex beasts as they grow. Program state incohesively spread across a bunch of variables, spuriously guar...