Search code examples
pythonneo4jpy2neo

Added a node to a graph connected via prompt with py2neo but MATCH (n) RETURN (n) shows empty graph in Neo4j browser


I am moving the first steps with py2neo.

I have created a graph via Neo4j Desktop

DBMS Name: Neo4j

password: Neo4j

and I have started it. Then I opened it with Neo4j browser, where it shows I am connected as user neo4j to bolt://localhost:7687.

enter image description here

Then, I connected to it from my prompt by typing

graph = Graph("bolt://localhost:7687", user="neo4j", password="Neo4j")

>>> graph
Graph('bolt://neo4j@localhost:7687')

I created a node

nicole = Node("person", name="Nicole", age=24)

>>> nicole
Node('person', age=24, name='Nicole')

and then I in my Neo4j browser, I expect to see my node if I type the query:

MATCH (n) RETURN (n)

But it returns nothing.

  1. Why?

  2. Also, if in my Chrome browser URL Bar I type http://localhost:7474/, it returns the same view of the Neo4j browser ( MATCH (n) RETURN (n) does not work even here )

enter image description here

but if in my Chrome browser URL Bar I type http://localhost:7687/, it returns a void window with just the message

not a WebSocket handshake request: missing upgrade

Why I don't get a Neo4j-browser-like view even in this second case?


Solution

  • As mentioned in the comments, you need to use the graph.create() to save the object in the database.

    graph = Graph("bolt://localhost:7687", user="neo4j", password="Neo4j")
    
    >>> graph
    Graph('bolt://neo4j@localhost:7687')
    nicole = Node("person", name="Nicole", age=24)
    
    >>> nicole
    Node('person', age=24, name='Nicole')
    
    >>> graph.create(nicole)
    
    

    You can read more here