如何在 Swift Firebase 中更新一个集合中的所有文档

Posted

技术标签:

【中文标题】如何在 Swift Firebase 中更新一个集合中的所有文档【英文标题】:How to update all Documents in one Collection in Swift Firebase 【发布时间】:2020-10-03 21:43:25 【问题描述】:

如何在不直接命名的情况下更新一个集合中的所有文档。 这是我的代码:

let db = Firestore.firestore()
             
db.collection((Auth.auth().currentUser?.email)!).document().updateData(["status":""])

  (err) in
     if err != nil 
 
                         
                         print("again failed")
                         return
                         
     else
         print("success")
     
     

【问题讨论】:

【参考方案1】:

Firestore 没有相当于 SQL“更新位置”查询的功能。您必须执行查询以获取所有文档、迭代结果并单独更新每个文档。如果您不提前知道文档 ID,则此过程没有捷径可走。

【讨论】:

以上是关于如何在 Swift Firebase 中更新一个集合中的所有文档的主要内容,如果未能解决你的问题,请参考以下文章