Consider user cart document with relationship with one-to-many products. Obviously Each product should also contain counts based on user choices. My question is how can we integrate count into specific products. Note:- Product should not be updated. Only Cart Document should be updated.
One solution that came to my mind is storing count as array of string {id: productId: count:2}. i.e.
Is there any other better way? With/without relationship?
I would probably have a cart Collection. Each item in the cart would be a Document, with a reference to the user and a Relationship with a single product, then a qty Attribute
This will require many documents for single user cart. That's why I am tried to keep all products in on doc
Well, if you want only one Document for the cart, the only option I see is to have an Array Attribute with the product IDs and quantites (as you suggested). You could also have another Attribute with a many-to-many Relationship with all the products, to avoid having to make a second request out to get the products each time.
Although I don't see any inherent issue with having many Documents for each cart
Recommended threads
- I'm getting error Invalid `url` param: I...
``` 2025-10-26T12:52:02.292Z [error] AppwriteException: Invalid `url` param: Invalid URI. Register your new client (vercel.com) as a new Web platform on your pr...
- Unknown column 'sourceSize' in 'field li...
After migrating from 1.6.1 to 1.7.4 I noticed this message in the logs: `appwrite-worker-stats-resources | 2025-10-26T10:32:38.289577112Z Failed: SQLSTATE[...
- Invalid document structure: Missing requ...
After migrating from 1.6.1 to 1.7.4 I noticed this message in the logs: appwrite-worker-audits | 2025-10-26T11:15:24.062537020Z Error processing a...