DROP
Drops elements from your database. The DROP effects the elements returned by the traversal.
You can use the drop on any traversal that returns a list of elements.
DROP will do nothing if the result of the expression is not a list of elements or if the list is empty.
Example 1: Removing a user node by ID
Dropping a node will also remove all related edges that are connected to it.
QUERY DeleteUserNode (user_id: ID) =>
DROP N<User>(user_id)
RETURN "Removed user node"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({ name: name, age: age, email: email })
RETURN user
See all 8 lines
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
yara = client.query( "CreateUser" , {
"name" : "Yara" ,
"age" : 24 ,
"email" : "yara@example.com" ,
})
yara_id = yara[ 0 ][ "user" ][ "id" ]
result = client.query( "DeleteUserNode" , { "user_id" : yara_id})
print (result)
See all 13 lines
Example 2: Removing outgoing neighbors
Use DROP on the outgoing traversal to delete connected neighbor nodes and the connecting edges.
QUERY DeleteOutgoingNeighbors (user_id: ID) =>
DROP N<User>(user_id)::Out<Follows>
RETURN "Removed outgoing neighbors"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({ name: name, age: age, email: email })
RETURN user
QUERY CreateRelationships (user1_id: ID, user2_id: ID) =>
follows <- AddE<Follows>::From(user1_id)::To(user2_id)
RETURN follows
See all 12 lines
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
lena = client.query( "CreateUser" , {
"name" : "Lena" ,
"age" : 30 ,
"email" : "lena@example.com" ,
})
lena_id = lena[ 0 ][ "user" ][ "id" ]
mason = client.query( "CreateUser" , {
"name" : "Mason" ,
"age" : 29 ,
"email" : "mason@example.com" ,
})
mason_id = mason[ 0 ][ "user" ][ "id" ]
client.query( "CreateRelationships" , {
"user1_id" : lena_id,
"user2_id" : mason_id,
})
result = client.query( "DeleteOutgoingNeighbors" , { "user_id" : lena_id})
print (result)
See all 25 lines
Example 3: Removing incoming neighbors
Delete any users that follow the target user by traversing incoming connections.
QUERY DeleteIncomingNeighbors (user_id: ID) =>
DROP N<User>(user_id)::In<Follows>
RETURN "Removed incoming neighbors"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({ name: name, age: age, email: email })
RETURN user
QUERY CreateRelationships (user1_id: ID, user2_id: ID) =>
follows <- AddE<Follows>::From(user1_id)::To(user2_id)
RETURN follows
See all 12 lines
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
ophelia = client.query( "CreateUser" , {
"name" : "Ophelia" ,
"age" : 32 ,
"email" : "ophelia@example.com" ,
})
ophelia_id = ophelia[ 0 ][ "user" ][ "id" ]
paul = client.query( "CreateUser" , {
"name" : "Paul" ,
"age" : 31 ,
"email" : "paul@example.com" ,
})
paul_id = paul[ 0 ][ "user" ][ "id" ]
client.query( "CreateRelationships" , {
"user1_id" : paul_id,
"user2_id" : ophelia_id,
})
result = client.query( "DeleteIncomingNeighbors" , { "user_id" : ophelia_id})
print (result)
See all 25 lines
Example 4: Removing outgoing edges only
Strip all follows edges that originate from the user without touching the neighbor nodes.
QUERY DeleteOutgoingEdges (user_id: ID) =>
DROP N<User>(user_id)::OutE<Follows>
RETURN "Removed outgoing edges"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({ name: name, age: age, email: email })
RETURN user
QUERY CreateRelationships (user1_id: ID, user2_id: ID) =>
follows <- AddE<Follows>::From(user1_id)::To(user2_id)
RETURN follows
See all 12 lines
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
riley = client.query( "CreateUser" , {
"name" : "Riley" ,
"age" : 26 ,
"email" : "riley@example.com" ,
})
riley_id = riley[ 0 ][ "user" ][ "id" ]
sam = client.query( "CreateUser" , {
"name" : "Sam" ,
"age" : 25 ,
"email" : "sam@example.com" ,
})
sam_id = sam[ 0 ][ "user" ][ "id" ]
client.query( "CreateRelationships" , {
"user1_id" : riley_id,
"user2_id" : sam_id,
})
result = client.query( "DeleteOutgoingEdges" , { "user_id" : riley_id})
print (result)
See all 25 lines
Example 5: Removing incoming edges only
Target follows edges pointing at the user while leaving the neighbor nodes untouched.
QUERY DeleteIncomingEdges (user_id: ID) =>
DROP N<User>(user_id)::InE<Follows>
RETURN "Removed incoming edges"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({ name: name, age: age, email: email })
RETURN user
QUERY CreateRelationships (user1_id: ID, user2_id: ID) =>
follows <- AddE<Follows>::From(user1_id)::To(user2_id)
RETURN follows
See all 12 lines
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from helix.client import Client
client = Client( local = True , port = 6969 )
uma = client.query( "CreateUser" , {
"name" : "Uma" ,
"age" : 28 ,
"email" : "uma@example.com" ,
})
uma_id = uma[ 0 ][ "user" ][ "id" ]
vince = client.query( "CreateUser" , {
"name" : "Vince" ,
"age" : 29 ,
"email" : "vince@example.com" ,
})
vince_id = vince[ 0 ][ "user" ][ "id" ]
client.query( "CreateRelationships" , {
"user1_id" : vince_id,
"user2_id" : uma_id,
})
result = client.query( "DeleteIncomingEdges" , { "user_id" : uma_id})
print (result)
See all 25 lines
Currently, Helix does not support deleting vectors from the graph.
As a workaround, you can delete the node and/or the edge that the vector is attached to.