iOS firebase database design problem : Best way to design chat app for cloud firestore?












0















Im working with Chat App. My firebase cloud store look like this



Messages = holding a whole messages from every users , every single messages from the beginning of service's release gathered here . It might contain 1,000,000,000,000 ~ messages



Messages | msg1                    | msgID = msg1
| msg2 | roomID = room03
| msg3 | content = "HELLO"
| ....... msg100,000,000 |

Rooms | room01 | roomID : room01
| room02 | memberIDs : user1 , user2 , user3
| room03 | messageIDs : msg1001 , msg2088 , msg991090


What i know : i can fetch 1 message from those billions of messages easily with



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in


What i Dont know , and i need to know
: How can i fetch all "messages" related to "one room"



What i Want : An array of 1,000 messages , ordered by timestamp



for example , room100 contain an array of messageIDs , up to 1,000 messagesIDs



| room100  |  messageIDs : msg1001 , msg2088 , msg991090 ..... msg9999999


Should i fetch it like this ?



for a in messageIDs {
db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in ......
}
}


I suppose not , this would created multiple , 1,000 parallel threads.
I cant predict which node would finished first , I would got the final result as unordered array of messages



Or Should i fetch it like this ?
Nested requests , for fully ordered messages



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1002")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1003")
.getDocuments() { (querySnapshot, err) in

*....... and so on , 1000 nested requests*
}
}
}
}
}


Whats the right way to fetch , validate and compare multiple groupID ????????????????










share|improve this question

























  • Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

    – Doug Stevenson
    Nov 13 '18 at 16:59











  • If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

    – Alex Mamo
    Nov 13 '18 at 17:16


















0















Im working with Chat App. My firebase cloud store look like this



Messages = holding a whole messages from every users , every single messages from the beginning of service's release gathered here . It might contain 1,000,000,000,000 ~ messages



Messages | msg1                    | msgID = msg1
| msg2 | roomID = room03
| msg3 | content = "HELLO"
| ....... msg100,000,000 |

Rooms | room01 | roomID : room01
| room02 | memberIDs : user1 , user2 , user3
| room03 | messageIDs : msg1001 , msg2088 , msg991090


What i know : i can fetch 1 message from those billions of messages easily with



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in


What i Dont know , and i need to know
: How can i fetch all "messages" related to "one room"



What i Want : An array of 1,000 messages , ordered by timestamp



for example , room100 contain an array of messageIDs , up to 1,000 messagesIDs



| room100  |  messageIDs : msg1001 , msg2088 , msg991090 ..... msg9999999


Should i fetch it like this ?



for a in messageIDs {
db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in ......
}
}


I suppose not , this would created multiple , 1,000 parallel threads.
I cant predict which node would finished first , I would got the final result as unordered array of messages



Or Should i fetch it like this ?
Nested requests , for fully ordered messages



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1002")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1003")
.getDocuments() { (querySnapshot, err) in

*....... and so on , 1000 nested requests*
}
}
}
}
}


Whats the right way to fetch , validate and compare multiple groupID ????????????????










share|improve this question

























  • Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

    – Doug Stevenson
    Nov 13 '18 at 16:59











  • If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

    – Alex Mamo
    Nov 13 '18 at 17:16
















0












0








0








Im working with Chat App. My firebase cloud store look like this



Messages = holding a whole messages from every users , every single messages from the beginning of service's release gathered here . It might contain 1,000,000,000,000 ~ messages



Messages | msg1                    | msgID = msg1
| msg2 | roomID = room03
| msg3 | content = "HELLO"
| ....... msg100,000,000 |

Rooms | room01 | roomID : room01
| room02 | memberIDs : user1 , user2 , user3
| room03 | messageIDs : msg1001 , msg2088 , msg991090


What i know : i can fetch 1 message from those billions of messages easily with



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in


What i Dont know , and i need to know
: How can i fetch all "messages" related to "one room"



What i Want : An array of 1,000 messages , ordered by timestamp



for example , room100 contain an array of messageIDs , up to 1,000 messagesIDs



| room100  |  messageIDs : msg1001 , msg2088 , msg991090 ..... msg9999999


Should i fetch it like this ?



for a in messageIDs {
db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in ......
}
}


I suppose not , this would created multiple , 1,000 parallel threads.
I cant predict which node would finished first , I would got the final result as unordered array of messages



Or Should i fetch it like this ?
Nested requests , for fully ordered messages



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1002")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1003")
.getDocuments() { (querySnapshot, err) in

*....... and so on , 1000 nested requests*
}
}
}
}
}


Whats the right way to fetch , validate and compare multiple groupID ????????????????










share|improve this question
















Im working with Chat App. My firebase cloud store look like this



Messages = holding a whole messages from every users , every single messages from the beginning of service's release gathered here . It might contain 1,000,000,000,000 ~ messages



Messages | msg1                    | msgID = msg1
| msg2 | roomID = room03
| msg3 | content = "HELLO"
| ....... msg100,000,000 |

Rooms | room01 | roomID : room01
| room02 | memberIDs : user1 , user2 , user3
| room03 | messageIDs : msg1001 , msg2088 , msg991090


What i know : i can fetch 1 message from those billions of messages easily with



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in


What i Dont know , and i need to know
: How can i fetch all "messages" related to "one room"



What i Want : An array of 1,000 messages , ordered by timestamp



for example , room100 contain an array of messageIDs , up to 1,000 messagesIDs



| room100  |  messageIDs : msg1001 , msg2088 , msg991090 ..... msg9999999


Should i fetch it like this ?



for a in messageIDs {
db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in ......
}
}


I suppose not , this would created multiple , 1,000 parallel threads.
I cant predict which node would finished first , I would got the final result as unordered array of messages



Or Should i fetch it like this ?
Nested requests , for fully ordered messages



db.collection("Messages").whereField("roomID", isEqualTo: "msg1001")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1002")
.getDocuments() { (querySnapshot, err) in

db.collection("Messages").whereField("roomID", isEqualTo: "msg1003")
.getDocuments() { (querySnapshot, err) in

*....... and so on , 1000 nested requests*
}
}
}
}
}


Whats the right way to fetch , validate and compare multiple groupID ????????????????







ios swift firebase google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 16:57









Doug Stevenson

73k983104




73k983104










asked Nov 13 '18 at 16:49









Hauja aeaHauja aea

81




81













  • Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

    – Doug Stevenson
    Nov 13 '18 at 16:59











  • If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

    – Alex Mamo
    Nov 13 '18 at 17:16





















  • Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

    – Doug Stevenson
    Nov 13 '18 at 16:59











  • If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

    – Alex Mamo
    Nov 13 '18 at 17:16



















Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

– Doug Stevenson
Nov 13 '18 at 16:59





Multiple queries don't create multiple threads. All queries are pipelined over a single connection in a single thread.

– Doug Stevenson
Nov 13 '18 at 16:59













If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

– Alex Mamo
Nov 13 '18 at 17:16







If you are interested, I have explained in one of my tutorials how you can create a Chat App using Cloud Firestore. You'll also find the way in which you can structure your database here.

– Alex Mamo
Nov 13 '18 at 17:16














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285846%2fios-firebase-database-design-problem-best-way-to-design-chat-app-for-cloud-fir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285846%2fios-firebase-database-design-problem-best-way-to-design-chat-app-for-cloud-fir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python