Queries

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 a method for each type of supported query.

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.

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.