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:

How can you work with a JSON value if you know nothing about it?

I have talked about the difficulty of typing certain JSON values coming from some APIs. The JSON is just very complicated. When I do that,...