【问题标题】:Can I use a Swift String Variable to get a Firebase document for a user?我可以使用 Swift 字符串变量为用户获取 Firebase 文档吗?
【发布时间】:2020-09-08 16:30:48
【问题描述】:

我正在尝试从我的数据库中读取一些数据,但我只想读取一个用户的数据,而不是读取所有用户的数据。

我尝试使用变量 userEmail 仅列出特定用户代码。

let userEmail = String((Auth.auth().currentUser?.email)!)


    func readArray() {

    print(userEmail)

    let docRef = Firestore.firestore().collection("users").document("\(userEmail)")
    //let docRef = db.collection("cities").document("SF")

    docRef.getDocument { (document, error) in
        if let document = document, document.exists {
            let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
            print("Document data: \(dataDescription)")
        } else {
            print("Document does not exist")
        }
    }
}

如果我将用户电子邮件输入为“test@gmail.com”,我可以获得用户的信息,但我知道这不适用于具有不同登录电子邮件的其他用户。

enter image description here

【问题讨论】:

  • 问题自行解决。只需要重置我的互联网连接....
  • 您能否详细说明问题是什么,我可以看到您正在连接 userEmail 的值,您的意思是这失败了吗?
  • @pessolato 是的,这是代码中唯一失败的部分,但由于某种原因,今天它决定工作。

标签: swift database firebase google-cloud-firestore


【解决方案1】:

问题自行解决。只需要重置我的互联网连接。这很奇怪,但事实证明您可以使用变量来查找您的特定文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 2012-06-20
    • 2020-03-03
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 2020-11-05
    相关资源
    最近更新 更多