- Building Web Applications with Python and Neo4j
- Sumit Gupta
- 529字
- 2021-07-16 13:39:13
Using the Neo4j shell
The Neo4j shell is a powerful interactive shell for interacting with the Neo4j database. It is used for performing the CRUD operations on graphs.
The Neo4j shell can be executed locally (on the same machine on which we have installed the Neo4j server) or remotely (by connecting the Neo4j shell to a remote sever).
By default, the Neo4j shell (<$NEO4J_HOME>/bin/neo4j-shell
) can be executed on the same machine on which the Neo4j server is installed, but the following configuration changes are required in <$NEO4J_HOME>/conf/neo4j.properties
to enable the connectivity of the Neo4j database from the remote machines:
remote_shell_enabled=true
: This configuration enables the propertyremote_shell_host=127.0.0.1
: This configuration enables and provides the IP address of the machine on which the Neo4j server is installedremote_shell_port=1337
: This configuration enables and defines the port for incoming connections
Let's talk about various other options provided by the Neo4j shell for connecting to the local Neo4j server:
neo4j-shell -path <PATH>
: This option shows the path of the database directory on the local file system. A new database will be created in case the given path does not contain a valid Neo4j database.neo4j-shell -pid <PID>
: This option connects to a specific process ID.neo4j-shell -readonly
: This option connects to the local database in theREAD ONLY
mode.neo4j-shell -c <COMMAND>
: This option executes a single Cypher statement and then the shell exits.neo4j-shell -file <FILE >
: This option reads the contents of the file (multiple Cypher CRUD operations), and then executes it.neo4j-shell –config - <CONFIG>
: This option reads the given configuration file (such asneo4j-server.properties
) from the specified location, and then starts the shell.
The following are the options for connecting to the remote Neo4j server:
neo4j-shell -port <PORT>
: This option connects to the server running on a port different to the default port (1337)neo4j-shell -host <HOST>
: This option shows the IP address or domain name of the remote host on which the Neo4j server is installed and running.
Let's move forward and get our hands dirty with the system.
To begin with and to make it simple, first we will insert the data, and then try to fetch the same data through the Neo4j shell.
Let's perform the following steps for running our Cypher queries in the Neo4j shell:
- Open your UNIX shell/console and execute
<$NEO4J_HOME>/bin/neo4j start
. This will start your Neo4j server in another process. - In the same console, execute
<$NEO4J_HOME>/bin/neo4j-shell
to start the Neo4j shell. - Next, execute the following set of statements on the console:
CREATE (movies:Movie {Name:"Noah", ReleaseYear:"2014"}); MATCH (n) return n; MATCH (n) delete n;
- You will see something like the following image on your console:
Yes, that's it…we are done!
We will pe deep into the details of the Cypher statements in the upcoming chapters, but let's see the results of each of the preceding Cypher statements:
CREATE (movies:Movie {Name:"Noah", ReleaseYear:"2014"});
: This statement creates a node with two attributes,Name:"Noah"
andReleaseYear:"2014"
, and a label,Movie
MATCH (n) return n;
: This statement searches the Neo4j database and prints all the nodes and their associated properties on the consoleMATCH (n) delete n;
: This statement searches the Neo4j database and deletes all the selected nodes
- SPSS數據挖掘與案例分析應用實踐
- C語言程序設計教程(第2版)
- PyTorch自然語言處理入門與實戰
- Java游戲服務器架構實戰
- Wireshark Network Security
- React.js Essentials
- SEO實戰密碼
- Python忍者秘籍
- C++面向對象程序設計習題解答與上機指導(第三版)
- RabbitMQ Essentials
- C語言程序設計上機指導與習題解答(第2版)
- Building Machine Learning Systems with Python(Second Edition)
- Arduino Wearable Projects
- Application Development with Parse using iOS SDK
- Spring Data JPA從入門到精通