Skip to main content

How do I select nodes in HelixDB?

Use N to select nodes from your graph by ID, type, or property values to begin traversals.
N<Type>(node_id)
N<Type>({field: value})

Example 1: Selecting a user by ID

QUERY GetUser (user_id: ID) =>
    user <- N<User>(user_id)
    RETURN user

QUERY CreateUser (name: String, age: U8, email: String) =>
    user <- AddN<User>({
        name: name,
        age: age,
        email: email
    })
    RETURN user
from helix.client import Client

client = Client(local=True, port=6969)

user = client.query("CreateUser", {
    "name": "Alice",
    "age": 25,
    "email": "alice@example.com",
})
user_id = user[0]["user"]["id"]

result = client.query("GetUser", {"user_id": user_id})
print(result)

Example 2: Selecting all users

QUERY GetAllUsers () =>
    users <- N<User>
    RETURN users
from helix.client import Client

client = Client(local=True, port=6969)

result = client.query("GetAllUsers")
print(result)

Example 3: Selecting nodes by property value

Select nodes by matching INDEX field values instead of ID. This is useful when you need to find nodes with specific property values.
QUERY GetUserByEmail (email: String) =>
    user <- N<User>({email: email})
    RETURN user
Property-based selection returns all nodes matching the specified INDEX field values. For more complex filtering conditions, use WHERE clauses.
You can also do specific property-based filtering, e.g., returning only ID, see the Property Filtering. You can also do aggregation steps, e.g., returning the count of nodes, see the Aggregations.