WHERE

Filter elements based on specific conditions.

::WHERE(<condition>)

The condition in the WHERE step must evaluate to a boolean value. If the condition is not met, the element will be filtered out.

Example

QUERY GetAdultUsers {
    // Filter to only users over 18
    adult_users <- N<User>::WHERE(_::{age}::GT(18))
    RETURN adult_users
}

For multiple conditions, see Multiple Conditional Steps.


Comparison Operations

The following operations can be used to compare values. EQ and NEQ can be used to compare strings, booleans, and numbers. GT, GTE, LT, and LTE can only be used to compare numbers.

String, Boolean, and Number Operations

OperationDescriptionExample
::EQ(value)Equals::WHERE(_::{status}::EQ("active"))
::NEQ(value)Not equals::WHERE(_::{age}::NEQ(25))

Number Operations

OperationDescriptionExample
::GT(value)Greater than::WHERE(_::{age}::GT(25))
::LT(value)Less than::WHERE(_::{age}::LT(30))
::GTE(value)Greater than or equal::WHERE(_::{rating}::GTE(4.5))
::LTE(value)Less than or equal::WHERE(_::{priority}::LTE(2))

EXISTS

Returns true if a traversal has any results. Otherwise, it returns false.

EXISTS(<traversal>)

Example

QUERY GetUsersWithFollowers() {
    users <- N<User>::WHERE(EXISTS(_::In<Follows>))
    RETURN users
}

RANGE

Get a range of elements from a traversal. The range is inclusive of the start, but exclusive of the end. e.g. RANGE(0, 10) will return 10 elements 0 through 9.

Both the start and end are required, and must be a positive integer.

::RANGE(start, end)

Example

QUERY GetRange(start: U32, end: U32) =>
    range <- N<User>::RANGE(start, end)
    RETURN range