
Imagine I have a collection of stock data, where there is a "symbol" attribute for each document. In my python function I want to query my collection to return a list of "symbol" attribute values that are unique.
i.e. If I had 3 documents and 2 of the documents had their symbol attribute as "AAPL", and the third document had their symbol attribute as "MSFT", the query would return a list of ["AAPL", "MSFT"]
TL;DR
Query the database to retrieve unique values of a specific attribute. To achieve this, the developer can use the `distinct` option in the `list_documents` method. Here's how to modify the existing code:
```python
docs = databases.list_documents(
DATABASE_ID,
COLLECTION_ID,
queries=[
Query.distinct(['symbol'])
]
)
```
By adding `Query.distinct(['symbol'])`, the query will return a list of unique values for the "symbol" attribute.
TypeScript
# Query Database for list of unique symbols
client = (
Client()
.set_endpoint('https://cloud.appwrite.io/v1')
.set_project(PROJECT_ID)
.set_key(APPWRITE_API_KEY)
)
databases = Databases(client)
docs = databases.list_documents(
DATABASE_ID,
COLLECTION_ID,
queries=[
# What queries do I add here?
Query.select(['symbol'])
]
)
Recommended threads
- Functions Failing Due to Installed Depen...
Hi team! Before anything, I am on the so far while we're in the planning phase of the app, and will be upgrading to pro soon. If there's a possibility that this...
- The new Bulk API and Realtime updates
It seems that the new Bulk API doesn't actually send realtime updates which is making a huge problem for me. I also wanted to know different is it deleting mul...
- Appwrite Python SDK Not Creating Relatio...
