Firebase Multilevel Child Query Android











up vote
0
down vote

favorite












How can i get All chats where Users contains a specific Uid



 Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200);

FirebaseRecyclerOptions<ChatMetaData> options =
new FirebaseRecyclerOptions.Builder<ChatMetaData>()
.setQuery(sItemQuery, ChatMetaData.class)
.setLifecycleOwner(this)
.build();


This is my DB Structure










share|improve this question




























    up vote
    0
    down vote

    favorite












    How can i get All chats where Users contains a specific Uid



     Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200);

    FirebaseRecyclerOptions<ChatMetaData> options =
    new FirebaseRecyclerOptions.Builder<ChatMetaData>()
    .setQuery(sItemQuery, ChatMetaData.class)
    .setLifecycleOwner(this)
    .build();


    This is my DB Structure










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      How can i get All chats where Users contains a specific Uid



       Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200);

      FirebaseRecyclerOptions<ChatMetaData> options =
      new FirebaseRecyclerOptions.Builder<ChatMetaData>()
      .setQuery(sItemQuery, ChatMetaData.class)
      .setLifecycleOwner(this)
      .build();


      This is my DB Structure










      share|improve this question















      How can i get All chats where Users contains a specific Uid



       Query sItemQuery = mDatabase.getReference().child("chats").limitToLast(200);

      FirebaseRecyclerOptions<ChatMetaData> options =
      new FirebaseRecyclerOptions.Builder<ChatMetaData>()
      .setQuery(sItemQuery, ChatMetaData.class)
      .setLifecycleOwner(this)
      .build();


      This is my DB Structure







      android firebase firebase-realtime-database firebaseui






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 15:11









      Frank van Puffelen

      218k25361386




      218k25361386










      asked Nov 10 at 14:53









      Wycliffe Kipkogei

      2115




      2115
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          You can't query across multiple levels like that. See Firebase Query Double Nested



          So while your current data structure makes it easy to find the current users in a chat, it doesn't make it easy to find the current chats for a user.



          For that you'll need to add an additional data structure. Something like:



          user_chats: {
          uid1: {
          chatid1: true,
          chatid2: true
          }
          uid2: {
          chatid2: true,
          chatid3: true
          }
          }


          With this additional structure, you can easily find the chats for the current user by reading /user_chats/$uid.



          Also see:




          • Firebase query if child of child contains a value






          share|improve this answer





















            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',
            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%2f53240131%2ffirebase-multilevel-child-query-android%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








            up vote
            2
            down vote













            You can't query across multiple levels like that. See Firebase Query Double Nested



            So while your current data structure makes it easy to find the current users in a chat, it doesn't make it easy to find the current chats for a user.



            For that you'll need to add an additional data structure. Something like:



            user_chats: {
            uid1: {
            chatid1: true,
            chatid2: true
            }
            uid2: {
            chatid2: true,
            chatid3: true
            }
            }


            With this additional structure, you can easily find the chats for the current user by reading /user_chats/$uid.



            Also see:




            • Firebase query if child of child contains a value






            share|improve this answer

























              up vote
              2
              down vote













              You can't query across multiple levels like that. See Firebase Query Double Nested



              So while your current data structure makes it easy to find the current users in a chat, it doesn't make it easy to find the current chats for a user.



              For that you'll need to add an additional data structure. Something like:



              user_chats: {
              uid1: {
              chatid1: true,
              chatid2: true
              }
              uid2: {
              chatid2: true,
              chatid3: true
              }
              }


              With this additional structure, you can easily find the chats for the current user by reading /user_chats/$uid.



              Also see:




              • Firebase query if child of child contains a value






              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                You can't query across multiple levels like that. See Firebase Query Double Nested



                So while your current data structure makes it easy to find the current users in a chat, it doesn't make it easy to find the current chats for a user.



                For that you'll need to add an additional data structure. Something like:



                user_chats: {
                uid1: {
                chatid1: true,
                chatid2: true
                }
                uid2: {
                chatid2: true,
                chatid3: true
                }
                }


                With this additional structure, you can easily find the chats for the current user by reading /user_chats/$uid.



                Also see:




                • Firebase query if child of child contains a value






                share|improve this answer












                You can't query across multiple levels like that. See Firebase Query Double Nested



                So while your current data structure makes it easy to find the current users in a chat, it doesn't make it easy to find the current chats for a user.



                For that you'll need to add an additional data structure. Something like:



                user_chats: {
                uid1: {
                chatid1: true,
                chatid2: true
                }
                uid2: {
                chatid2: true,
                chatid3: true
                }
                }


                With this additional structure, you can easily find the chats for the current user by reading /user_chats/$uid.



                Also see:




                • Firebase query if child of child contains a value







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 15:11









                Frank van Puffelen

                218k25361386




                218k25361386






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240131%2ffirebase-multilevel-child-query-android%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

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues