- Cypher
- Python SDK
Copy
Ask AI
// Create a node Person (Jane) - Edge (knows) - node Person (John)
CREATE (:Person {name: 'Jane'})-[:KNOWS]->(:Person {name: 'John'})
// Commit the changes
COMMIT
CREATE query above, the two nodes having label Person and the edge were created in the same query. You can also create nodes and queries one by one (less efficient).Copy
Ask AI
// Create two nodes Person : Jane and John
CREATE (:Person {name: 'John'})
CREATE (:Person {name: 'Jane'})
// You need to commit the changes after node creation
COMMIT
// Match Jane and John nodes to create edge of label KNOWS between them
MATCH (n:Person {name: 'Jane'}), (m:Person {name: 'John'})
CREATE (n)-[e:KNOWS]->(m)
// Commit the changes
COMMIT
In the case you create the nodes then the edges, you need to commit your changes after node creation.
Copy
Ask AI
# Create a node Person (Jane) - Edge (knows) - node Person (John)
client.query("CREATE (:Person {name: 'Jane'})-[:KNOWS]->(:Person {name: 'John'})")
# Commit the changes
client.query("COMMIT")
CREATE query above, the two nodes having label Person and the edge were created in the same query. You can also create nodes and queries one by one (less efficient).Copy
Ask AI
# Create two nodes Person : Jane and John
client.query("CREATE (:Person {name: 'John'})")
client.query("CREATE (:Person {name: 'Jane'})")
# You need to commit the changes after node creation
client.query("COMMIT")
# Create edge of label KNOWS between Jane and John
client.query("""
MATCH (n:Person {name: 'Jane'}), (m:Person {name: 'John'})
CREATE (n)-[e:KNOWS]->(m)
""")
# Commit the change
client.query("COMMIT")
In the case you create the nodes then the edges, you need to commit your changes after node creation.

