Problems with firebase logic





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-3















I have a problems and I'm pretty sure people here can help me.



I'm a beginner in coding (1 or 2 month only) and I have a big difficulty to figured how the logic work.



Here's my problems:



I have 3 collections in firebase:




  1. Tournament


  2. Tour


  3. Notes



-> I have multiple tournament, everyone contain 5 different tours and each tournament contain note take by user.



So my problems is, how can I related theses 3 collections and show only example:



Tournament A -> Tour: A, B, C, D, E -> User notes for every tournament?



I just need help on how I need to think to group everything.










share|improve this question




















  • 1





    Are you using Firestore or realtime database

    – Yogesh Tandel
    Jan 3 at 12:41











  • I'm using firestore!

    – Alexandre
    Jan 3 at 12:50











  • I think i found the best solution!

    – Alexandre
    Jan 3 at 12:54













  • Sure.. go ahead. let me know if you need anything

    – Yogesh Tandel
    Jan 3 at 12:54






  • 1





    If I create 3 collections with the same document id! Do you think that would work??

    – Alexandre
    Jan 3 at 12:57


















-3















I have a problems and I'm pretty sure people here can help me.



I'm a beginner in coding (1 or 2 month only) and I have a big difficulty to figured how the logic work.



Here's my problems:



I have 3 collections in firebase:




  1. Tournament


  2. Tour


  3. Notes



-> I have multiple tournament, everyone contain 5 different tours and each tournament contain note take by user.



So my problems is, how can I related theses 3 collections and show only example:



Tournament A -> Tour: A, B, C, D, E -> User notes for every tournament?



I just need help on how I need to think to group everything.










share|improve this question




















  • 1





    Are you using Firestore or realtime database

    – Yogesh Tandel
    Jan 3 at 12:41











  • I'm using firestore!

    – Alexandre
    Jan 3 at 12:50











  • I think i found the best solution!

    – Alexandre
    Jan 3 at 12:54













  • Sure.. go ahead. let me know if you need anything

    – Yogesh Tandel
    Jan 3 at 12:54






  • 1





    If I create 3 collections with the same document id! Do you think that would work??

    – Alexandre
    Jan 3 at 12:57














-3












-3








-3








I have a problems and I'm pretty sure people here can help me.



I'm a beginner in coding (1 or 2 month only) and I have a big difficulty to figured how the logic work.



Here's my problems:



I have 3 collections in firebase:




  1. Tournament


  2. Tour


  3. Notes



-> I have multiple tournament, everyone contain 5 different tours and each tournament contain note take by user.



So my problems is, how can I related theses 3 collections and show only example:



Tournament A -> Tour: A, B, C, D, E -> User notes for every tournament?



I just need help on how I need to think to group everything.










share|improve this question
















I have a problems and I'm pretty sure people here can help me.



I'm a beginner in coding (1 or 2 month only) and I have a big difficulty to figured how the logic work.



Here's my problems:



I have 3 collections in firebase:




  1. Tournament


  2. Tour


  3. Notes



-> I have multiple tournament, everyone contain 5 different tours and each tournament contain note take by user.



So my problems is, how can I related theses 3 collections and show only example:



Tournament A -> Tour: A, B, C, D, E -> User notes for every tournament?



I just need help on how I need to think to group everything.







java android firebase google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 14:06









Frank van Puffelen

246k31392420




246k31392420










asked Jan 3 at 12:09









AlexandreAlexandre

32




32








  • 1





    Are you using Firestore or realtime database

    – Yogesh Tandel
    Jan 3 at 12:41











  • I'm using firestore!

    – Alexandre
    Jan 3 at 12:50











  • I think i found the best solution!

    – Alexandre
    Jan 3 at 12:54













  • Sure.. go ahead. let me know if you need anything

    – Yogesh Tandel
    Jan 3 at 12:54






  • 1





    If I create 3 collections with the same document id! Do you think that would work??

    – Alexandre
    Jan 3 at 12:57














  • 1





    Are you using Firestore or realtime database

    – Yogesh Tandel
    Jan 3 at 12:41











  • I'm using firestore!

    – Alexandre
    Jan 3 at 12:50











  • I think i found the best solution!

    – Alexandre
    Jan 3 at 12:54













  • Sure.. go ahead. let me know if you need anything

    – Yogesh Tandel
    Jan 3 at 12:54






  • 1





    If I create 3 collections with the same document id! Do you think that would work??

    – Alexandre
    Jan 3 at 12:57








1




1





Are you using Firestore or realtime database

– Yogesh Tandel
Jan 3 at 12:41





Are you using Firestore or realtime database

– Yogesh Tandel
Jan 3 at 12:41













I'm using firestore!

– Alexandre
Jan 3 at 12:50





I'm using firestore!

– Alexandre
Jan 3 at 12:50













I think i found the best solution!

– Alexandre
Jan 3 at 12:54







I think i found the best solution!

– Alexandre
Jan 3 at 12:54















Sure.. go ahead. let me know if you need anything

– Yogesh Tandel
Jan 3 at 12:54





Sure.. go ahead. let me know if you need anything

– Yogesh Tandel
Jan 3 at 12:54




1




1





If I create 3 collections with the same document id! Do you think that would work??

– Alexandre
Jan 3 at 12:57





If I create 3 collections with the same document id! Do you think that would work??

– Alexandre
Jan 3 at 12:57












1 Answer
1






active

oldest

votes


















0














There is no single correct data model, as (with all NoSQL solutions) the best data model depends on the use-cases of your app.



But as far as I can see, you have two major options:




  1. Nest the child collections

  2. Connect documents by embedding parent IDs


Nest the child collections



Firestore is a database that contains collections of documents. Each document can contain subcollections under it. Given that your data model is hierarchical, that means you can nest them like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
Notes (collection)
Notes1_1_1 (document)


Now each tournament has its own tours, and each tour has its own notes. You can access them in isolation: so just read the notes for a single tour, without needing to build a query for that.



Connect documents by embedding parent IDs



The alternative is to have three top-level collections, and to connect each child document to its parent by embedding the parent ID into it, like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
TournamentID: Tournament1
Notes (collection)
Notes1_1_1 (document)
TourID: Tour1_1


With this model you can get all Tours for a Tournament by querying ref.collection("Tours").where("TournamentID", "==", "Tournament1").



An advantage of the second model is that you can access tours across all tournaments, while in the first model you can only access the tours for one tournament at a time (at least until Firestore implements collection group queries).



A disadvantage of the second model is that you'll always need to query, and that it is less scaleable as far as writes are concerned.






share|improve this answer
























  • Thank you very much for your time. I think the second options is the best for me.

    – Alexandre
    Jan 3 at 14:39












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%2f54022033%2fproblems-with-firebase-logic%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There is no single correct data model, as (with all NoSQL solutions) the best data model depends on the use-cases of your app.



But as far as I can see, you have two major options:




  1. Nest the child collections

  2. Connect documents by embedding parent IDs


Nest the child collections



Firestore is a database that contains collections of documents. Each document can contain subcollections under it. Given that your data model is hierarchical, that means you can nest them like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
Notes (collection)
Notes1_1_1 (document)


Now each tournament has its own tours, and each tour has its own notes. You can access them in isolation: so just read the notes for a single tour, without needing to build a query for that.



Connect documents by embedding parent IDs



The alternative is to have three top-level collections, and to connect each child document to its parent by embedding the parent ID into it, like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
TournamentID: Tournament1
Notes (collection)
Notes1_1_1 (document)
TourID: Tour1_1


With this model you can get all Tours for a Tournament by querying ref.collection("Tours").where("TournamentID", "==", "Tournament1").



An advantage of the second model is that you can access tours across all tournaments, while in the first model you can only access the tours for one tournament at a time (at least until Firestore implements collection group queries).



A disadvantage of the second model is that you'll always need to query, and that it is less scaleable as far as writes are concerned.






share|improve this answer
























  • Thank you very much for your time. I think the second options is the best for me.

    – Alexandre
    Jan 3 at 14:39
















0














There is no single correct data model, as (with all NoSQL solutions) the best data model depends on the use-cases of your app.



But as far as I can see, you have two major options:




  1. Nest the child collections

  2. Connect documents by embedding parent IDs


Nest the child collections



Firestore is a database that contains collections of documents. Each document can contain subcollections under it. Given that your data model is hierarchical, that means you can nest them like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
Notes (collection)
Notes1_1_1 (document)


Now each tournament has its own tours, and each tour has its own notes. You can access them in isolation: so just read the notes for a single tour, without needing to build a query for that.



Connect documents by embedding parent IDs



The alternative is to have three top-level collections, and to connect each child document to its parent by embedding the parent ID into it, like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
TournamentID: Tournament1
Notes (collection)
Notes1_1_1 (document)
TourID: Tour1_1


With this model you can get all Tours for a Tournament by querying ref.collection("Tours").where("TournamentID", "==", "Tournament1").



An advantage of the second model is that you can access tours across all tournaments, while in the first model you can only access the tours for one tournament at a time (at least until Firestore implements collection group queries).



A disadvantage of the second model is that you'll always need to query, and that it is less scaleable as far as writes are concerned.






share|improve this answer
























  • Thank you very much for your time. I think the second options is the best for me.

    – Alexandre
    Jan 3 at 14:39














0












0








0







There is no single correct data model, as (with all NoSQL solutions) the best data model depends on the use-cases of your app.



But as far as I can see, you have two major options:




  1. Nest the child collections

  2. Connect documents by embedding parent IDs


Nest the child collections



Firestore is a database that contains collections of documents. Each document can contain subcollections under it. Given that your data model is hierarchical, that means you can nest them like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
Notes (collection)
Notes1_1_1 (document)


Now each tournament has its own tours, and each tour has its own notes. You can access them in isolation: so just read the notes for a single tour, without needing to build a query for that.



Connect documents by embedding parent IDs



The alternative is to have three top-level collections, and to connect each child document to its parent by embedding the parent ID into it, like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
TournamentID: Tournament1
Notes (collection)
Notes1_1_1 (document)
TourID: Tour1_1


With this model you can get all Tours for a Tournament by querying ref.collection("Tours").where("TournamentID", "==", "Tournament1").



An advantage of the second model is that you can access tours across all tournaments, while in the first model you can only access the tours for one tournament at a time (at least until Firestore implements collection group queries).



A disadvantage of the second model is that you'll always need to query, and that it is less scaleable as far as writes are concerned.






share|improve this answer













There is no single correct data model, as (with all NoSQL solutions) the best data model depends on the use-cases of your app.



But as far as I can see, you have two major options:




  1. Nest the child collections

  2. Connect documents by embedding parent IDs


Nest the child collections



Firestore is a database that contains collections of documents. Each document can contain subcollections under it. Given that your data model is hierarchical, that means you can nest them like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
Notes (collection)
Notes1_1_1 (document)


Now each tournament has its own tours, and each tour has its own notes. You can access them in isolation: so just read the notes for a single tour, without needing to build a query for that.



Connect documents by embedding parent IDs



The alternative is to have three top-level collections, and to connect each child document to its parent by embedding the parent ID into it, like this:



Tournaments (collection)
Tournament1 (document)
Tours (collection)
Tour1_1 (document)
TournamentID: Tournament1
Notes (collection)
Notes1_1_1 (document)
TourID: Tour1_1


With this model you can get all Tours for a Tournament by querying ref.collection("Tours").where("TournamentID", "==", "Tournament1").



An advantage of the second model is that you can access tours across all tournaments, while in the first model you can only access the tours for one tournament at a time (at least until Firestore implements collection group queries).



A disadvantage of the second model is that you'll always need to query, and that it is less scaleable as far as writes are concerned.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 14:15









Frank van PuffelenFrank van Puffelen

246k31392420




246k31392420













  • Thank you very much for your time. I think the second options is the best for me.

    – Alexandre
    Jan 3 at 14:39



















  • Thank you very much for your time. I think the second options is the best for me.

    – Alexandre
    Jan 3 at 14:39

















Thank you very much for your time. I think the second options is the best for me.

– Alexandre
Jan 3 at 14:39





Thank you very much for your time. I think the second options is the best for me.

– Alexandre
Jan 3 at 14:39




















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%2f54022033%2fproblems-with-firebase-logic%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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory