ewicOriginal post
Web Developer
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"]
Summary
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.