DEV Community

Cover image for New Operators to Query Documents More Efficiently
Torsten Dittmann for Appwrite

Posted on

New Operators to Query Documents More Efficiently

Query operators are essential to search and retrieve data from Appwrite. To allow more advanced queries, we have added new operators to the mix with Appwrite 1.3.

🤔 New to Appwrite?

Appwrite is an open-source back-end-as-a-service that abstracts all the complexity of building a modern application by providing you with a set of REST, GraphQL, and Realtime APIs for your core back-end needs. Appwrite takes the heavy lifting for developers and handles user authentication and authorization, databases, file storage, cloud functions, webhooks, and much more!

Operators

This section will introduce each of these operators and provide examples of how they affect results.

isNull

The isNull operator is used to query for documents with null or missing values. This operator is handy when you need to identify incomplete data or records that lack specific fields. For example, if you're managing customer data and want to find customers who haven't provided their email addresses, you can use the isNull operator to retrieve those records.

Query.isNull('email')
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Torsten Dittmann"
    "email": null,
    // ...
  }
]
Enter fullscreen mode Exit fullscreen mode

isNotNull

The isNotNull operator, on the other hand, is used to query for documents with values. This operator is helpful when you want to exclude records with missing fields from your query results.

Query.isNotNull('email')
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Christy Jacob"
    "email": "christy@example.com",
    // ...
  }
]
Enter fullscreen mode Exit fullscreen mode

between

The between operator is used to query for documents within a range of values. This operator is helpful when retrieving records that fall between two specified values. It can be used with both string and numeric attributes.

Query.between('age', 28, 48)
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Torsten Dittmann"
    "age": 30,
    //...
  }
]
Enter fullscreen mode Exit fullscreen mode

startsWith

The startsWith operator is used to query for documents that begin with a specified string.

Query.startsWith('name','Chris')
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Christy Jacob"
    //...
  }
]
Enter fullscreen mode Exit fullscreen mode

endsWith

Conversely, the endsWith operator is used to query for documents that end with a specified string.

Query.endsWith('name','mann')
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Torsten Dittmann"
    //...
  }
]
Enter fullscreen mode Exit fullscreen mode

select

The select operator is used to select specific fields from a document. This operator is useful when you want to retrieve only certain fields from a document and exclude others.

Query.select(['name', 'email'])
Enter fullscreen mode Exit fullscreen mode
[
  {
    "name": "Torsten Dittmann",
    "email": null
  },
  {
    "name": "Christy Jacob",
    "email": "christy@example.com"
  }
]
Enter fullscreen mode Exit fullscreen mode

Learn More

Adding these database operators to Appwrite has improved the ability of developers to query data more efficiently. It allows for more complex queries with less code, which reduces development time and increases productivity.

Check out our documentation for more information and the release announcement for details on other awesome new features in the latest version of Appwrite.

You can also use the following resources to learn more and get help:

Top comments (1)

Collapse
 
henningsummer profile image
Henning Summer

Interesting...