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:

Moving Backgrounds With Mouse Position

Let's say you wanted to move the background-position on an element as you mouse over it to give the design a little pizzazz. You have ...