Chapter 3. Manipulating the Database

In the previous chapters, you learned how to query and work with data stored in a database. Yet, you don't know how to modify the database because, as you are going to see, the processes of creating, updating, and deleting data are topics strictly related to all the notions we have learned so far. In this chapter, we will learn the following:

  • How to use Neo4j Browser to prototype and test your queries quickly
  • The syntax and usage of the CREATE clause
  • How to merge data with an existing database
  • How to delete data from a database

Using Neo4j Browser

Neo4j Browser is a very useful tool that is distributed with Neo4j. It's a web-based shell client, which we can use to interact in real time with a Neo4j Server database without configuring or programming anything other than Cypher. Here, no Java code is needed. The purpose of Neo4j Browser is to provide an easy interface for prototyping databases and testing queries. It can be accessed by following these steps:

  1. Start Neo4j Community. You can download the latest version from the Neo4j download page at http://www.neo4j.org/download.
  2. Choose a database location path and click on the Start button.
  3. Wait a few seconds while the database is created.
    Using Neo4j Browser
  4. Click on the link that appears in the Status panel (for example, http://localhost:7474/) to open Neo4j Browser.

Now you should see your preferred browser open the web page as shown in the following screenshot:

Using Neo4j Browser

At the top of the page, there is the shell prompt. Here, you can write the Cypher queries you want to be executed in real time against the database. The results will be shown as output in the panel below. For example, let's take a look at the content of the database by writing the following query:

MATCH (n) RETURN n

The panel below shifts and shows the query result. On the right-hand side of the result panel, we have two buttons: one that shows the graph visualization and one that shows the grid visualization:

Using Neo4j Browser

As we saw in the first chapter, Neo4j Server supports a REST API. So, if you're going to use a Neo4j database server, you'll use a REST API to interact with it. If you're going to interact with the database server using a programming language that is supported by a driver of your choice, note that this driver (whether PHP, C#, Python, or any other) will wrap REST calls to the Neo4j REST API. Although the REST API is not strictly necessary if you aren't a driver developer, it can be really useful to know that Neo4j Browser can also be used to test REST API calls when something goes wrong with the driver. A REST API is a layer that runs on a database server that actually performs queries/modifications on databases. Java, C#, and other drivers just abstract calls to this API, allowing programmers to write their applications without worrying about the stack and the protocol used to communicate with the database.

For example, you can send the previous query to Neo4j with REST by typing the following code in the prompt:

:POST /db/data/cypher { "query": "MATCH (n) RETURN n" }

Neo4j Browser returns the following result:

{
  "columns": [
    "n"
  ],
  "data": []
}

The database is empty so we get zero rows. It's time to fill the database with new nodes and relationships.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.244.250