[英]Firebase iOS - Query with one part of the compound key
In my Firebase database I use a compound key as the ID for one-to-one conversations in the following format 'UID1_UID2' sorted lexicographically. 在我的Firebase数据库中,我使用复合密钥作为按字母顺序排序的以下格式“ UID1_UID2”的一对一对话的ID。
When I want to load all conversations via the iOS client for a particular user (UID1) how can I query Firebase when the compound key consists of two combined user IDs. 当我想通过iOS客户端为特定用户(UID1)加载所有对话时,当复合键包含两个组合的用户ID时,如何查询Firebase。
queryStartingAt("UID1_").queryEndingAt("UID1_")
will return all conversations UID1_ started. 将返回所有已开始的UID1_对话。
You should be structuring your data as 您应该将数据结构化为
conversation: UID1_UID2
Compound keys are not that great of an idea. 复合键并不是一个好主意。 Please consult this part of the documentation that explains how to best model a chat / conversation structure.
请查阅文档的此部分,该部分说明如何最好地建模聊天/对话结构。
Relevant excerpt demonstrating how to structure data for chats: 有关摘录的演示如何构造聊天数据的方法:
{
// Chats contains only meta info about each conversation
// stored under the chats's unique ID
"chats": {
"one": {
"title": "Historical Tech Pioneers",
"lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
"timestamp": 1459361875666
},
"two": { ... },
"three": { ... }
},
// 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": { ... }
},
// Messages are separate from data we may want to iterate quickly
// but still easily paginated and queried, and organized by chat
// conversation ID
"messages": {
"one": {
"m1": {
"name": "eclarke",
"message": "The relay seems to be malfunctioning.",
"timestamp": 1459361875337
},
"m2": { ... },
"m3": { ... }
},
"two": { ... },
"three": { ... }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.