构建聊天应用程序的NoSQL数据库(使用FireBase) [英] Structure a NoSQL database for a chat application (using FireBase)
问题描述
为了理解如何在性能的基础上构建数据库,我做了大量的研究。我试图去规范化这个结构,结果如下:
{
chats:{
1:{
10:{
conversationId:x123332
},
17 :{
conversationId:x124442
}
}
},
会话:{
x123332:{
message1:{
time:12344556,
text:你好,你好吗?,
userId:10
},
message2:{
time:12344560,
text:Good,
userId:1
}
}
}
}
数字1,10,17是样本用户标识。
我的问题是,这可以用更好的方式来组织吗?我们的目标是随着应用程序用户的增长而扩大规模,并且仍然可以获得最佳的性能。解决方案
看起来像这样:
$ b $ pre $ userMessages:
{simplelogin:1:
{ simplelogin:2:
{messageId1:
{uid:simplelogin:1,
body:Hello!,
timestamp: Firebase.ServerValue.TIMESTAMP},
messageId2:{
uid:simplelogin:2,
body:Hey!,
timestamp :Firebase.ServerValue.TIMESTAMP}
}
}
}
这个结构来自于这个结构。本教程使用firebase构建一个像slack一样的应用程序: 如果你想要更具体的东西,更多的信息将是有帮助的。 Coming from years of using relational databases, i am trying to develop a pretty basic chat/messaging app using FireBase FireBase uses a NoSQL data structure approach using JSON formatted strings. I did a lot of research in order to understand how to structure the database with performance in mind. I have tried to "denormalize" the structure and ended up with the following: The numbers 1, 10, 17 are sample user id's. My question is, can this be structured in a better way? The goal is to scale up as the app users grow and still get the best performance possible. One case for storing messages could look something like this: Here is a fireslack example this structure came from. This tutorial builds an app like slack using firebase:
https://thinkster.io/angularfire-slack-tutorial If you want something more specific, more information would be helpful. 这篇关于构建聊天应用程序的NoSQL数据库(使用FireBase)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
https://thinkster.io/angularfire-slack
{
"chats" : {
"1" : {
"10" : {
"conversationId" : "x123332"
},
"17": {
"conversationId" : "x124442"
}
}
},
"conversations" : {
"x123332" : {
"message1" : {
"time" : 12344556,
"text" : "hello, how are you?",
"userId" : 10
},
"message2" : {
"time" : 12344560,
"text" : "Good",
"userId" : 1
}
}
}
}
"userMessages":
{ "simplelogin:1":
{ "simplelogin:2":
{ "messageId1":
{ "uid": "simplelogin:1",
"body": "Hello!",
"timestamp": Firebase.ServerValue.TIMESTAMP },
"messageId2": {
"uid": "simplelogin:2",
"body": "Hey!",
"timestamp": Firebase.ServerValue.TIMESTAMP }
}
}
}