user2300301
user2300301

Reputation: 71

Neo4j relationships without nodes throw error

Due to a unforeseen shutdown (and /or and error in my code) I have relationships in the database without nodes attached to it.

I think what happened was that used a MATCH statement to look up a node and subsequently a MERGE to create a relationship. For some reasons however the Match did not return a results, but the MERGE did create a relationship (apparently with a non existing node). See example below:

MATCH (image:Image {id:{param}.id}) FOREACH (tagName in {param}.tags | MERGE (tag:Tag {tag:tagName}) MERGE (image)-[:IS_TAGGED_AS]->(tag) // Here it creates a relationship even if no matching image is found. )

When I run a simple query I receive the following message:

While loading relationships for Node[xx] a Relationship[xx] was encountered that had startNode: 0 and endNode: 0, i.e. which had neither start nor end node as the node we're loading relationships for

I can reference the node and the relationship by Id (although the relationship does not return results) but can't Delete them.

Is there anything I can do to fix this?

Ideally I create a query to select all 'bad' relationships and delete them.

I am working on Neo4j 2.3.0.

Upvotes: 0

Views: 662

Answers (1)

Oliver Frost
Oliver Frost

Reputation: 827

Are you sure that relationships can be created without nodes? That doesn't make sense to me. The way MERGE works is that it will match a node or relationship if it exists, otherwise it will try create a new one.

If you add PROFILE to the start of your query in the Neo4j Browser, you can see the execution plan for a query. You will see that nodes are matched first and then the relationships are matched and/or created afterwards.

Upvotes: 0

Related Questions