New Operators to Query Documents More Efficiently
Tags: opensource, programming, news
Published: 2023-04-12 13:13:26

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](https://appwrite.io/) 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.

```js
Query.isNull('email')
```

```json
[
  {
    "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.

```js
Query.isNotNull('email')
```

```json
[
  {
    "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.

```js
Query.between('age', 28, 48)
```

```json
[
  {
    "name": "Torsten Dittmann"
    "age": 30,
    //...
  }
]
```

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

```js
Query.startsWith('name','Chris')
```

```json
[
  {
    "name": "Christy Jacob"
    //...
  }
]
```

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

```js
Query.endsWith('name','mann')
```

```json
[
  {
    "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. 

```js
Query.select(['name', 'email'])
```

```json
[
  {
    "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](https://appwrite.io/docs/databases-queries) for more information and [the release announcement](https://dev.to/appwrite/join-celebrations-appwrite-13-ships-relationships-57fc) 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](https://github.com/appwrite/appwrite)
- 📜 [Appwrite Docs](https://appwrite.io/docs)
- 💬 [Discord Community](https://appwrite.io/discord)