
In my appwrite application, I have a collection containing Stores
(with attributes like name
, address
,...), and then a different collection containing Products
(with attributes like name
, price
, owner_store_id
,...)
At some point I need to show all products of a given store and I have the following two options:
- Using listDocuments with a query that returns only the products having
owner_store_id
= the id of the wanted store (and in this case, I would also create an index on theProducts
collection for theowner_store_id
key - Storing the ids of the owned products in a
owned_products[]
attribute of theStores
collection (by adding them each time a new product is created) and then calling getDocument for each of the ids in theowned_products
array of the wanted store
Which one of the two ways would you say is better? I mean, if they are equivalent efficiency-wise I would go for the first one so I can avoid storing the owned_products array for each store, but are they actually equivalent? Or getting documents by index is still more efficient than getting them by query even if the query is on an indexed key?

server-side, getDocument() is faster because that goes to the cache rather than the database.
The trade-off, though is the multiple getDocument()
calls you'll need to make vs the one listDocuments()
call so... ⚖️

Oh ok I didn't thought about the impact of having to do multiple requests instead of a single one, thank you! I'll probably go fot the Query option then to avoid having to keep the same information duplicated in two different places of the database then
Recommended threads
- Help with 409 Error on Relationship Setu...
I ran into a 409 document_already_exists issue. with AppWrite so I tried to debug. Here's what I've set up: Collection A has 3 attributes and a two-way 1-to-m...
- Database Double Requesting Error.
I am getting error for creating new document in an collection with new ID.unique() then too getting error of existing document. When button is pressed one docum...
- JSON and Object Support in Collection do...
I am working with Next.Js and Appwrite Cloud, I am relatively New to Appwrite but i have noticed there is no direct support of JSON and Object support in attrib...
