The MERGE clause
The MERGE clause will find or create a pattern in the database. It is good practice to split your MERGE statements into one clause per node or relationship.
Time to try out a MERGE query on your Neo4j database, graph.
This exercise is part of the course
Graph RAG with LangChain and Neo4j
Exercise instructions
- Complete the Cypher statement to find or create
PersonandCoursenodes withnameandtitleproperties, respectively, and joined by anENROLLED_INrelationship. - Query
graphusing your own name and with the course title provided.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Modify the your Cypher statement
cypher = """
____ (p:____ {name: $name})
____ (c:____ {title: $title})
MERGE (p)-[:ENROLLED_IN]->(c)
RETURN p.name AS name
"""
# Add your name to the query
result = graph.query(cypher,
{"name": "____", "title": "Graph RAG with LangChain and Neo4j"}
)
for record in result:
print(record['name'])