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:

Appboy/appboy-fb-messenger-bot

Building a Messenger bot for Appboy About Messenger bots Introduction On April 12, 2016, Facebook launched its Messenger Platform, intende...