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 attributes should be returned from a document. 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 documents without relationships
By default, documents return only their own fields:
Load all relationship data
Use the *
wildcard to load all fields from related documents:
Select specific relationship fields
For precise control, select only specific fields from related documents:
Load nested relationships
You can also load relationships of relationships:
Use selection patterns
Pattern | Description | Use case |
["field1", "field2"] | Specific attributes only | Minimize response size |
["*"] | All document attributes | Get complete document data |
["*", "relationName.*"] | Document + all relationship fields | Load document with complete related data |
["field1", "relationName.field2"] | Specific fields from document and relationships | Precise data loading |
["*", "relationName.field1", "relationName.field2"] | All document 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 documents 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 documents.
Related documents
By default, relationship attributes contain only document IDs. To load the actual related document data, you must explicitly include relationship fields in your select query. Learn more about relationship performance optimization.
Comparison operators
Equal
Returns document if attribute is equal to any value in the provided array.
Not equal
Returns document if attribute is not equal to any value in the provided array.
Less than
Returns document if attribute is less than the provided value.
Less than or equal
Returns document if attribute is less than or equal to the provided value.
Greater than
Returns document if attribute is greater than the provided value.
Greater than or equal
Returns document if attribute is greater than or equal to the provided value.
Between
Returns document if attribute value falls between the two values. The boundary values are inclusive and can be strings or numbers.
Null checks
Is null
Returns documents where attribute value is null.
Is not null
Returns documents where attribute value is not null.
String operations
Starts with
Returns documents if a string attribute starts with a substring.
Ends with
Returns documents if a string attribute ends with a substring.
Contains
Returns documents if the array attribute contains the specified elements or if a string attribute contains the specified substring.
Search
Searches string attributes for provided keywords. Requires a full-text index on queried attributes.
Logical operators
AND
Returns document if it matches all of the nested sub-queries in the array passed in.
OR
Returns document if it matches any of the nested sub-queries in the array passed in.
Ordering
Order descending
Orders results in descending order by attribute. Attribute must be indexed.
Order ascending
Orders results in ascending order by attribute. Attribute 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 documents that match either of these combined conditions.