Skip to content

Instantly share code, notes, and snippets.

@jeanmidevacc
Created May 12, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanmidevacc/f07cddb3d64c5df14637153d0d9b28c2 to your computer and use it in GitHub Desktop.
Save jeanmidevacc/f07cddb3d64c5df14637153d0d9b28c2 to your computer and use it in GitHub Desktop.
neo4j_set_relationships.py
from neo4j import GraphDatabase
# Declare the connector to the graph database
uri = "bolt://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "pwd"), encrypted=False)
# Build the query to build the relationship
query = f'''
MATCH (u:User), (s:Song)
WHERE u.id = "id of the user" AND s.id = "id of the song"
CREATE (u)-[: BOOKMARKED]->(s)
RETURN u,s
'''
with driver.session() as session:
session.run(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment