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')
[
{
"name": "Torsten Dittmann"
"email": null,
// ...
}
]
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')
[
{
"name": "Christy Jacob"
"email": "christy@example.com",
// ...
}
]
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)
[
{
"name": "Torsten Dittmann"
"age": 30,
//...
}
]
startsWith
The startsWith
operator is used to query for documents that begin with a specified string.
Query.startsWith('name','Chris')
[
{
"name": "Christy Jacob"
//...
}
]
endsWith
Conversely, the endsWith
operator is used to query for documents that end with a specified string.
Query.endsWith('name','mann')
[
{
"name": "Torsten Dittmann"
//...
}
]
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'])
[
{
"name": "Torsten Dittmann",
"email": null
},
{
"name": "Christy Jacob",
"email": "christy@example.com"
}
]
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:
- 🚀 Appwrite GitHub
- 📜 Appwrite Docs
- 💬 Discord Community
Top comments (1)
Interesting...