Many list endpoints in Appwrite allow you to filter, sort, and paginate results using queries. Appwrite provides a common set of syntax to build queries.
Query class
Appwrite SDKs provide a Query
class to help you build queries. The Query
class has methods for each type of supported query operation.
Building queries
Queries are passed to an endpoint through the queries
parameter as an array of query strings, which can be generated using the Query
class.
Each query method is logically separated via AND
operations. For OR
operation, pass multiple values into the query method separated by commas. For example Query.equal('title', ['Avatar', 'Lord of the Rings'])
will fetch the movies Avatar
or Lord of the Rings
.
Default pagination behavior
By default, results are limited to the first 25 items. You can change this through pagination.
Query operators
Select
The select
operator allows you to specify which columns should be returned from a row. This is essential for optimizing response size, controlling which relationship data loads, and only retrieving the data you need.
Select relationship data
With opt-in relationship loading, you must explicitly select relationship data. This gives you fine-grained control over performance and payload size.
Get rows without relationships
By default, rows return only their own fields:
Load all relationship data
Use the *
wildcard to load all fields from related rows:
Select specific relationship fields
For precise control, select only specific fields from related rows:
Load nested relationships
You can also load relationships of relationships:
Use selection patterns
Pattern | Description | Use case |
["field1", "field2"] | Specific columns only | Minimize response size |
["*"] | All row columns | Get complete row data |
["*", "relationName.*"] | Row + all relationship fields | Load row with complete related data |
["field1", "relationName.field2"] | Specific fields from row and relationships | Precise data loading |
["*", "relationName.field1", "relationName.field2"] | All row fields + specific relationship fields | Partial relationship loading |
["relationName.*", "relationName.nestedRelation.*"] | Nested relationship loading | Load relationships of relationships |
Optimize performance
Optimize response size - Only select the fields you actually need. Smaller responses are faster to transfer and parse.
Control relationship loading - Related rows are not loaded by default. Use explicit selection to load only the relationships you need.
Reduce database load - Selecting fewer fields reduces database processing time, especially for large rows.
Related rows
By default, relationship columns contain only row IDs. To load the actual related row data, you must explicitly include relationship fields in your select query. Learn more about relationship performance optimization.
Comparison operators
Equal
Returns row if column is equal to any value in the provided array.
Not equal
Returns row if column is not equal to any value in the provided array.
Less than
Returns row if column is less than the provided value.
Less than or equal
Returns row if column is less than or equal to the provided value.
Greater than
Returns row if column is greater than the provided value.
Greater than or equal
Returns row if column is greater than or equal to the provided value.
Between
Returns row if column value falls between the two values. The boundary values are inclusive and can be strings or numbers.
Null checks
Is null
Returns rows where column value is null.
Is not null
Returns rows where column value is not null.
String operations
Starts with
Returns rows if a string column starts with a substring.
Ends with
Returns rows if a string column ends with a substring.
Contains
Returns rows if the array column contains the specified elements or if a string column contains the specified substring.
Search
Searches string columns for provided keywords. Requires a full-text index on queried columns.
Logical operators
AND
Returns row if it matches all of the nested sub-queries in the array passed in.
OR
Returns row if it matches any of the nested sub-queries in the array passed in.
Ordering
Order descending
Orders results in descending order by column. Column must be indexed.
Order ascending
Orders results in ascending order by column. Column must be indexed.
Pagination
Limit
Limits the number of results returned by the query. Used for pagination.
Offset
Offset the results returned by skipping some of the results. Used for pagination.
Cursor after
Places the cursor after the specified resource ID. Used for pagination.
Cursor before
Places the cursor before the specified resource ID. Used for pagination.
Complex queries
You can create complex queries by combining AND and OR operations. For example, to find items that are either books under $20 or magazines under $10:
This example demonstrates how to combine OR
and AND
operations. The query uses Query.or()
to match either condition: books under $20 OR magazines under $10. Each condition within the OR is composed of two AND conditions - one for the category and one for the price threshold. The database will return rows that match either of these combined conditions.