Posts

Mass removal of Edges and Nodes - DELETE

Deleting of Nodes:  To delete a node it should have no relationships Delete all nodes and relationships match (n)-[r]-() delete n, r Delete all nodes which have no relationships match (n) delete n Delete only ExampleNodes which have no relationships match (n:ExampleNode) delete n Delete all relationships match (n)-[r]-() delete r Delete only ExampleRelation relationships match (n)-[r:ExampleRelation]-() delete r

Stopping and Starting the Neo4j Database

Controlling the service System services are controlled with the systemctl command. It accepts a number of commands and follows the format: systemctl {start|stop|restart} neo4j you may find that you need to prefix the systemctl command with sudo like: sudo systemctl stop neo4j looking at the output of the status command we get :   sudo systemctl status neo4j ● neo4j.service - Neo4j Graph Database    Loaded: loaded (/etc/systemd/system/neo4j.service; enabled; vendor preset: enabled)    Active: active (running) since Thu 2020-07-23 09:53:29 UTC; 1h 33min ago  Main PID: 958 (pre-neo4j.sh)     Tasks: 64    Memory: 14.3G       CPU: 22min 1.740s    CGroup: /system.slice/neo4j.service            ├─ 958 /bin/bash /etc/neo4j/pre-neo4j.sh            ├─ 996 /bin/sh /etc/neo4j/reset-password-aws.sh            ├─ 997 /usr/bin/java -cp /va...

Neo4j - Managing Relationship names

In a Graph Database Relationships between the nodes are considered to be as important, if not more important than the nodes themselves. A Relationship joins two nodes or 'loops-back' to the same node. The relationship can be created or deleted but cannot be renamed. How to delete relationship MATCH (n { name: 'Greg' })-[r:KNOWS]->() DELETE r To rename a Relationship you do a simultaneous create and delete. Create a new relationship and delete the old as below: Rename relationship MATCH (n)-[rel:IS_CONNECTED_TO]->(m) MERGE (n)-[:KNOWS]->(m) DELETE rel MATCH (n)-[rel:IS_CONNECTED_TO]->(m) WITH rel CALL apoc.refactor.setType(rel, 'KNOWS') YIELD input, output RETURN *

Neo4j - Node Labels

Labels are the 'TABLES' of the Graph database world. Here's some useful methods of manipulating Labels. Rather than delete and create your Nodes in Neo4j just to change the label, it may be easier to try one of the two methods below: Rename node - Method 1: MATCH (s:OldLabel) SET s:NewLabel REMOVE s:OldLabel Rename node - Method 2: MATCH (n:OldLabel) WITH COLLECT(n) AS nodes CALL apoc.refactor.rename.label('OldLabel','NewLabel'[,nodes]) YIELD errorMessages AS eMessages RETURN eMessages; Do you have any more ways of 'renaming' Nodes in Neo4j? Nodes can also have more than one Label. Here is how to add and remove a Label on a Node where the only matching property is {name : 'Greg'} How to add a new label MATCH (n { name: 'Greg' }) SET n:NewLabel RETURN n.name, labels(n) AS labels How to remove a label MATCH (n { name: 'Greg' }) REMOVE n:OldLabel RETURN n.name, labels(n) AS labels

Neo4j

Neo4j is a graph database. It is not like Oracle or SQL Server - no tables and primary keys with associated foreign keys. Sounds .......... scary Sounds........... different But when you map out a workflow on a piece of paper, drawing boxes and circles and joinging them with lines, you create a graph. It's what comes naturally.