Ad

Flutter Firestore Update Documents

I have an App where the user can buy Tickets. And in Firestore the Tickets are represented by documents so each ticket has it's own document. What I want to do is when the user wants to buy 5 Tickets I need a way to pick 5 random documents where the status is available and set them to sold. Is there a specific way to do that?

Ad

Answer

You can retrieve 5 random tickets with a Firestore-query with .limit(5) in a list. After that you can loop to the list and get the id of each ticket and update each ticket to status "sold".

Ad
source: stackoverflow.com
Ad