#Query the list of values for a specific attribute but remove duplicates

7 messages · Page 1 of 1 (latest)

exotic aspen
#

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"]

exotic aspen
#
# 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'])
    ] 
)

exotic aspen
#

If I have over 1000 documents in my database/collection, but there are only 3 different symbol values for the attribute, I dont want to have to query my entire database and then store the symbol attribute as a set to get the unique values, this seems very inefficient

vast river
#

what type of attribute is your symbol?

exotic aspen
#

String attribute

vast river
#

What I understand is that you want to delete specific document , if the condition meet when there are duplicated value on symbol column?

#

If I am correct, then why not to set that attribute index into unique type? So that when the user try to create a document they will inform then that this kind of data is not unique or it’s already exist in your collection.