简体   繁体   English

Flutter Firestore 更新文档

[英]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.在 Firestore 中,工单由文档表示,因此每张工单都有自己的文档。 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.我想要做的是当用户想要购买 5 张门票时,我需要一种方法来选择 5 个状态可用的随机文档并将它们设置为已售出。 Is there a specific way to do that?有没有具体的方法可以做到这一点?

You can retrieve 5 random tickets with a Firestore-query with.limit(5) in a list.您可以使用 Firestore 查询 with.limit(5) 在列表中检索 5 张随机票。 After that you can loop to the list and get the id of each ticket and update each ticket to status "sold".之后,您可以循环到列表并获取每张票的 id 并将每张票更新为状态“已售出”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM