【发布时间】:2020-08-07 06:35:40
【问题描述】:
我使用了 Firebase 文档提供的示例代码,它会打印出错误消息。我不知道问题是在代码中还是在数据库结构中,因为还有子集合。在这种情况下,我正在尝试检索“Home Title”字段,但是我听说这是不可能的(我可能错了),所以我试图检索“Sample Wedding”文档,但无济于事。这是我第一次使用 Swift 和 Firestore 编写项目。
这是我的代码:
let db = Firestore.firestore()
let docRef = db.collection("Weddings").document("Sample Wedding")
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")
}
这是我的数据库结构: ]
【问题讨论】:
-
具体发生在哪里以及发生了什么错误?
-
它打印出“文档不存在”,即使应该有一个。
标签: ios swift firebase google-cloud-firestore