Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Lab 6 — Troubleshoot Common Cypher and Connection Errors

Topic 02: Cypher Fundamentals

Objective: Troubleshoot database errors and problems faced in database administration activities (A3, LO2).

Goal

Deliberately trigger the errors you will meet in real work — syntax errors, constraint violations, a delete blocked by relationships, a type mismatch and a failed connection — then read each message and apply the correct fix.

What you'll build

A troubleshooting log recording each error message, its root cause and the fix that resolved it.

Tools: Neo4j Browser, Cypher, Neo4j Desktop

Files in this folder

File What it is
solution.cypher every Cypher statement from the lab (14 steps), runnable in order

Dataset

This lab uses a shared dataset from ../data/:

  • ../data/topic2_movie.dump

The .dump files are distributed through the course Google Drive folder (the link is on your LMS course page); the CSVs are in the repository.

Steps

Step 1

Trigger a syntax error by misspelling a clause. Read the caret in the message — it points at the offending token.

MACH (p:Person) RETURN p

Step 2

Fix the syntax error and confirm the query now runs.

MATCH (p:Person) RETURN p LIMIT 5

Step 3

Trigger a delete error: create a node with a relationship, then try to delete the node alone.

MERGE (m:Movie {title: 'The Matrix'})
MERGE (p:Person {name: 'Jane Doe'})
MERGE (p)-[:ACTED_IN]->(m);
MATCH (p:Person {name: 'Jane Doe'})
DELETE p

Step 4

Read the message 'Cannot delete node, because it still has relationships', then apply the fix with DETACH DELETE.

MATCH (p:Person {name: 'Jane Doe'})
DETACH DELETE p

Step 5

Create a uniqueness constraint so you can trigger and diagnose a constraint violation.

CREATE CONSTRAINT person_name_unique IF NOT EXISTS
FOR (p:Person) REQUIRE p.name IS UNIQUE

Step 6

Attempt to CREATE a duplicate node and read the ConstraintValidationFailed message.

CREATE (p:Person {name: 'Tom Hanks'})
RETURN p

Step 7

Apply the fix: use MERGE instead of CREATE so the existing node is matched rather than duplicated.

MERGE (p:Person {name: 'Tom Hanks'})
RETURN p

Step 8

Trigger a type mismatch by comparing a string property against a number, and observe that the query returns no rows rather than failing loudly — the most dangerous class of error.

MATCH (m:Movie)
WHERE m.released = '1999'
RETURN count(m) AS matchedRowsProbablyZero

Step 9

Apply the fix by converting the type explicitly, and compare the row count with the previous step.

MATCH (m:Movie)
WHERE m.released = toInteger('1999')
RETURN count(m) AS matchedRows

Step 10

Diagnose a null-handling trap: a property that does not exist is null, and null never equals anything, so use IS NULL and IS NOT NULL to test it.

MATCH (m:Movie)
WHERE m.tagline IS NULL
RETURN count(m) AS moviesWithoutTagline

Step 11

Simulate a connection failure: stop the DBMS in Neo4j Desktop, run any query, and read the ServiceUnavailable message. Restart the DBMS and re-run to confirm recovery.

MATCH (n) RETURN count(n)

Step 12

Inspect the currently running queries and the active transactions — the first place to look when the database appears to hang.

SHOW TRANSACTIONS

Step 13

Check the query log location and the database status when diagnosing a problem you cannot reproduce interactively.

SHOW DATABASES

Step 14

Drop the constraint you created so it does not interfere with later labs, and record every error and fix in your troubleshooting log.

DROP CONSTRAINT person_name_unique IF EXISTS

Test it

Your troubleshooting log contains at least five distinct error messages with the root cause and fix for each, the DETACH DELETE succeeds where DELETE failed, and the toInteger comparison returns a non-zero row count where the string comparison returned zero.

Deliverable

Submit a screenshot or export showing the verification above, together with the Cypher or Python you ran.