如何批量更新数组?
因此,我正在创建一个出勤应用程序,其中有一个名为与会者的列表,其中包含所有参加讲座的学生的列表。
List<String> attendees = [uid0, uid1, uid2];
学生数据模型如下
Student(
List<String> attendance = [at0, at1]; //this is the list of lectures attended
String name;
)
,每个学生的文档名称是他们的用户ID
如何通过 batch()
函数更新每个学生的列表?
So I am creating an attendance app in which there is a list named attendees which contains the list of all students attending the lecture.
List<String> attendees = [uid0, uid1, uid2];
and the student data model is as follows
Student(
List<String> attendance = [at0, at1]; //this is the list of lectures attended
String name;
)
and the document name of every student is their user-id
How do I update the list of every student via the batch()
function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您已经有一个包含
user-id
的与会者列表,正如您提到的userId
将是 Firestore 中的documentId
一样。因此,您可以执行循环并直接
更新
您的文档,然后使用commit
应用您的更改。一些注意事项:
I assume you already have a list of attendees that contains
user-id
as you mentioned theuserId
would be thedocumentId
in Firestore.Therefore, you can do a loop and
update
your doc directly and then usecommit
to apply your changes.A few notes: