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.

    import { Client, Databases, Query } from "appwrite";
    
    const client = new Client()
        .setEndpoint('https://cloud.appwrite.io/v1')
        .setProject('<PROJECT_ID>');
    
    const databases = new Databases(client);
    
    databases.listDocuments(
        '<DATABASE_ID>',
        '[COLLECTION_ID]',
        [
            Query.equal('title', ['Avatar', 'Lord of the Rings']),
            Query.greaterThan('year', 1999)
        ]
    );