cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

a small question about deleting specific group without deleteing all the other nodes of the graph

verachkaverachk
Graph Buddy

Hello, can you please help me understand the correct query of deleting specific group of nodes inside a graph,

I want to be able to delete only this: CellType(blue) and the function(red) that is connected to it, and the variables(light green) without deleting the whole graph, for example I want to delete at first the group that i've marked in 1 and only her, and after for example i want to delete  the group i've marked in 2 ,but without deleting the whole graph they connect to. is there an elegant and generic way to do it?:) 

verachkaverachk_1-1658499899863.png

 

 

 

1 ACCEPTED SOLUTION

try this:

match (n:Function)
where id(n) in [156, 163]
match (n)--(m)
detach delete n, m

View solution in original post

5 REPLIES 5

glilienfield
Ninja
Ninja

From the look of the graph data, you can match on the function node (red) and delete it and its immediate neighboring nodes. 

match (n:Function{id: 0})
match (n)--(m)
detach delete n, m

verachkaverachk
Graph Buddy

Hello,

this query doesn't work for some reason, any other idea? or maybe the syntax not correct?

Vera.

I assume you changed the ‘id’ property condition to a property and value that identifies the ‘function’ node you want to delete. If you don’t have a unique identifier, you can use the neo4j id. 

what doesn’t work about it? Can you provide some details?

do you have a small script I can use to generate the data for testing? 

verachkaverachk
Graph Buddy

verachkaverachk_0-1658595869026.pngverachkaverachk_1-1658595892789.png

The data of the current graph looks like this:

n
1
{
  "identity": 149,
  "labels": [
    "Variable"
  ],
  "properties": {
    "variableName": "x"
  }
}
2
{
  "identity": 150,
  "labels": [
    "Function"
  ],
  "properties": {
    "expression": "x"
  }
}
3
{
  "identity": 151,
  "labels": [
    "CellType"
  ],
  "properties": {
    "name": "inputCell",
    "transformType": "INPUT_TO_ANALOG"
  }
}
4
{
  "identity": 152,
  "labels": [
    "CellInstance"
  ],
  "properties": {
    "yCoordinate": 2.7,
    "xCoordinate": 2.6
  }
}
5
{
  "identity": 153,
  "labels": [
    "CellInstance"
  ],
  "properties": {
    "yCoordinate": 2.7,
    "xCoordinate": 2.6
  }
}
6
{
  "identity": 154,
  "labels": [
    "Variable"
  ],
  "properties": {
    "variableName": "x"
  }
}
7
{
  "identity": 155,
  "labels": [
    "Variable"
  ],
  "properties": {
    "variableName": "y"
  }
}
8
{
  "identity": 156,
  "labels": [
    "Function"
  ],
  "properties": {
    "expression": "x+y"
  }
}
9
{
  "identity": 157,
  "labels": [
    "CellType"
  ],
  "properties": {
    "name": "addition",
    "transformType": "ANALOG_TO_ANALOG"
  }
}
10
{
  "identity": 158,
  "labels": [
    "CellInstance"
  ],
  "properties": {
    "yCoordinate": 2.7,
    "xCoordinate": 2.6
  }
}
11
{
  "identity": 159,
  "labels": [
    "Connection"
  ],
  "properties": {
    "delay": 0
  }
}
12
{
  "identity": 160,
  "labels": [
    "Connection"
  ],
  "properties": {
    "delay": 0
  }
}
13
{
  "identity": 161,
  "labels": [
    "Variable"
  ],
  "properties": {
    "variableName": "x"
  }
}
14
{
  "identity": 162,
  "labels": [
    "Variable"
  ],
  "properties": {
    "variableName": "y"
  }
}
15
{
  "identity": 163,
  "labels": [
    "Function"
  ],
  "properties": {
    "expression": "x+y"
  }
}
16
{
  "identity": 164,
  "labels": [
    "CellType"
  ],
  "properties": {
    "name": "addition",
    "transformType": "ANALOG_TO_ANALOG"
  }
}
17
{
  "identity": 165,
  "labels": [
    "CellInstance"
  ],
  "properties": {
    "yCoordinate": 2.7,
    "xCoordinate": 2.6
  }
}

 

try this:

match (n:Function)
where id(n) in [156, 163]
match (n)--(m)
detach delete n, m