在 firebase 数据库的 firebase 文档中,有关于展平数据库的信息,并以消息应用程序为例。
https://firebase.google.com/docs/database/web/structure-data
// Conversation members are easily accessible
// and stored by chat conversation ID
"members": {
// we'll talk about indices like this below
"one": {
"ghopper": true,
"alovelace": true,
"eclarke": true
},
"two": { ... },
"three": { ... }
},
在“成员”/“一个”下,每个键是聊天中参与成员的姓名。我很确定在 firebase 数据库中有一个 getKey 方法来获取每个键。
我已经以类似的方式设置了我的数据库(使用 firestore 而不是 firebase),但是每个聊天都是一个唯一标识符,文档包含聊天的成员,其中键是他们的 firebase auth id,例如。
var docsref: DocumentReference?
docsref = self.defaultStore?.colleection("chats").document(chatID)
docsref?.getDocument { (document, error) in
if let _ = document {
print("document!.data()")
} else {
print("Document does not exist")
}
}
当我输出时:
print(document!.data())
我得到 ["2mHuccccxxxxxxxxxxxk4wkIAt33": 1] 这是参与聊天成员之一的 firebase 身份验证代码和一个布尔值。
我想得到那把钥匙,但不知道如何。
谢谢。
我不确定它是否是确切的语法,但self.defaultStore?.colleection
可能是双 E 的拼写错误。也可能是您遗漏了一步。您正在进入 chatID,并且希望在成员内部输出密钥而不实际访问它。我会在之后访问成员.document(chatID)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句