Welcome to our comprehensive guide on Neo4j Cypher, a powerful and easy-to-use graph query language that allows you to traverse and query your data within Neo4j databases. Let's embark on this exciting journey together!
Neo4j Cypher is the declarative graph query language that Neo4j uses to interact with its graph database. It's designed to simplify the process of working with complex, interconnected data. Think of it as a powerful tool that helps you navigate through a vast network of data, making it easy to find the information you need.
Neo4j Cypher is chosen for its simplicity, scalability, and high performance. It allows you to perform complex graph operations in a straightforward manner, making it an ideal choice for real-world applications.
💡 Pro Tip: In Neo4j, nodes represent individual items in a graph, like people, places, or things.
CREATE (n:Label)Replace Label with the type of node you want to create.
📝 Note: Relationships in Neo4j represent the connections between nodes.
CREATE (n1:Label1)-[:RELATIONSHIP_TYPE]->(n2:Label2)Replace LABEL1 and LABEL2 with the types of the connecting nodes, and RELATIONSHIP_TYPE with the relationship type.
MATCH (n:Label)
RETURN nReplace Label with the type of the node you want to query.
MATCH (n1:Label1)-[:RELATIONSHIP_TYPE*]->(n2:Label2)
RETURN n1, n2This query finds all paths from a Label1 node to a Label2 node, regardless of the number of intermediary relationships.
MATCH (n:Label)
WHERE n.property = 'value'
RETURN nFilter the results based on a property of the node.
Consider a social network where users can follow each other. Here's how you might create and query this data using Neo4j Cypher:
CREATE (user1:User {name: 'Alice', age: 30})
CREATE (user2:User {name: 'Bob', age: 25})
CREATE (user3:User {name: 'Charlie', age: 22})
CREATE (user1)-[:FOLLOWS]->(user2)
CREATE (user1)-[:FOLLOWS]->(user3)
MATCH (user:User)
WHERE user.age > 20
RETURN userThis creates three users and connects them with FOLLOWS relationships. It then queries for users older than 20.
Which Cypher query creates a node of type `User` with the name 'John' and age 28?
Happy coding! 💡 📝 🎯