Topic 02: Cypher Fundamentals
Objective: Troubleshoot database errors and problems faced in database administration activities (A3, LO2).
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.
A troubleshooting log recording each error message, its root cause and the fix that resolved it.
Tools: Neo4j Browser, Cypher, Neo4j Desktop
| File | What it is |
|---|---|
solution.cypher |
every Cypher statement from the lab (14 steps), runnable in order |
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.
Trigger a syntax error by misspelling a clause. Read the caret in the message — it points at the offending token.
MACH (p:Person) RETURN pFix the syntax error and confirm the query now runs.
MATCH (p:Person) RETURN p LIMIT 5Trigger 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 pRead 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 pCreate 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 UNIQUEAttempt to CREATE a duplicate node and read the ConstraintValidationFailed message.
CREATE (p:Person {name: 'Tom Hanks'})
RETURN pApply the fix: use MERGE instead of CREATE so the existing node is matched rather than duplicated.
MERGE (p:Person {name: 'Tom Hanks'})
RETURN pTrigger 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 matchedRowsProbablyZeroApply 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 matchedRowsDiagnose 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 moviesWithoutTaglineSimulate 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)Inspect the currently running queries and the active transactions — the first place to look when the database appears to hang.
SHOW TRANSACTIONSCheck the query log location and the database status when diagnosing a problem you cannot reproduce interactively.
SHOW DATABASESDrop 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 EXISTSYour 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.
Submit a screenshot or export showing the verification above, together with the Cypher or Python you ran.