Trying to query across collections in google Firestore









up vote
1
down vote

favorite












I am trying to retrieve data from one collection depending on data held in another. If the userUID in my attendance collection equals the userUID in my student collection I would like to retrieve the name of the student. Is this possible?










share|improve this question























  • if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
    – Mohammed Farhan
    Aug 20 at 12:56










  • can I combine these queries of two collections into one query or how is this possible
    – Sean Gallagher
    Aug 20 at 13:10










  • No its not possible to combine queries of two collection into one query.
    – Mohammed Farhan
    Aug 21 at 4:43














up vote
1
down vote

favorite












I am trying to retrieve data from one collection depending on data held in another. If the userUID in my attendance collection equals the userUID in my student collection I would like to retrieve the name of the student. Is this possible?










share|improve this question























  • if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
    – Mohammed Farhan
    Aug 20 at 12:56










  • can I combine these queries of two collections into one query or how is this possible
    – Sean Gallagher
    Aug 20 at 13:10










  • No its not possible to combine queries of two collection into one query.
    – Mohammed Farhan
    Aug 21 at 4:43












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to retrieve data from one collection depending on data held in another. If the userUID in my attendance collection equals the userUID in my student collection I would like to retrieve the name of the student. Is this possible?










share|improve this question















I am trying to retrieve data from one collection depending on data held in another. If the userUID in my attendance collection equals the userUID in my student collection I would like to retrieve the name of the student. Is this possible?







firebase google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 20 at 12:54









Doug Stevenson

65.7k77997




65.7k77997










asked Aug 20 at 12:37









Sean Gallagher

406




406











  • if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
    – Mohammed Farhan
    Aug 20 at 12:56










  • can I combine these queries of two collections into one query or how is this possible
    – Sean Gallagher
    Aug 20 at 13:10










  • No its not possible to combine queries of two collection into one query.
    – Mohammed Farhan
    Aug 21 at 4:43
















  • if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
    – Mohammed Farhan
    Aug 20 at 12:56










  • can I combine these queries of two collections into one query or how is this possible
    – Sean Gallagher
    Aug 20 at 13:10










  • No its not possible to combine queries of two collection into one query.
    – Mohammed Farhan
    Aug 21 at 4:43















if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
– Mohammed Farhan
Aug 20 at 12:56




if you have a document with same userId in attendance and student collection, then you can query student using WhereEqualTo(fieldName,value) like db.collection("student") .whereEqualTo("userId", "idValue").get()
– Mohammed Farhan
Aug 20 at 12:56












can I combine these queries of two collections into one query or how is this possible
– Sean Gallagher
Aug 20 at 13:10




can I combine these queries of two collections into one query or how is this possible
– Sean Gallagher
Aug 20 at 13:10












No its not possible to combine queries of two collection into one query.
– Mohammed Farhan
Aug 21 at 4:43




No its not possible to combine queries of two collection into one query.
– Mohammed Farhan
Aug 21 at 4:43












2 Answers
2






active

oldest

votes

















up vote
0
down vote













This is currently not possible with Firestore. Firestore queries are limited to a documents in a single collection. You would have to perform multiple gets or queries.






share|improve this answer




















  • Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
    – Sean Gallagher
    Aug 20 at 13:16










  • As I said, write multiple queries to get the data you need.
    – Doug Stevenson
    Aug 20 at 13:20










  • is there anyway to write a function within a query to retrieve data maybe.
    – Sean Gallagher
    Aug 20 at 13:56










  • No, you have to perform multiple queries.
    – Doug Stevenson
    Aug 20 at 13:58










  • And to add to this is there any way to write queries within other queries
    – Sean Gallagher
    Aug 20 at 14:22

















up vote
0
down vote













According to multiple Google Firebase engineers, querying across collections is not at all possible, despite the Firestore documentation that says:




If you need to query data across collections, use
root-level collections.




https://firebase.google.com/docs/firestore/data-model?authuser=3



I would suggest that Google rewrite this part of their documentation because that sentences literally infers the opposite. It should read along the lines of:




If you need to query data across collections, not happening.







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%2f51930931%2ftrying-to-query-across-collections-in-google-firestore%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This is currently not possible with Firestore. Firestore queries are limited to a documents in a single collection. You would have to perform multiple gets or queries.






    share|improve this answer




















    • Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
      – Sean Gallagher
      Aug 20 at 13:16










    • As I said, write multiple queries to get the data you need.
      – Doug Stevenson
      Aug 20 at 13:20










    • is there anyway to write a function within a query to retrieve data maybe.
      – Sean Gallagher
      Aug 20 at 13:56










    • No, you have to perform multiple queries.
      – Doug Stevenson
      Aug 20 at 13:58










    • And to add to this is there any way to write queries within other queries
      – Sean Gallagher
      Aug 20 at 14:22














    up vote
    0
    down vote













    This is currently not possible with Firestore. Firestore queries are limited to a documents in a single collection. You would have to perform multiple gets or queries.






    share|improve this answer




















    • Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
      – Sean Gallagher
      Aug 20 at 13:16










    • As I said, write multiple queries to get the data you need.
      – Doug Stevenson
      Aug 20 at 13:20










    • is there anyway to write a function within a query to retrieve data maybe.
      – Sean Gallagher
      Aug 20 at 13:56










    • No, you have to perform multiple queries.
      – Doug Stevenson
      Aug 20 at 13:58










    • And to add to this is there any way to write queries within other queries
      – Sean Gallagher
      Aug 20 at 14:22












    up vote
    0
    down vote










    up vote
    0
    down vote









    This is currently not possible with Firestore. Firestore queries are limited to a documents in a single collection. You would have to perform multiple gets or queries.






    share|improve this answer












    This is currently not possible with Firestore. Firestore queries are limited to a documents in a single collection. You would have to perform multiple gets or queries.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 20 at 12:56









    Doug Stevenson

    65.7k77997




    65.7k77997











    • Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
      – Sean Gallagher
      Aug 20 at 13:16










    • As I said, write multiple queries to get the data you need.
      – Doug Stevenson
      Aug 20 at 13:20










    • is there anyway to write a function within a query to retrieve data maybe.
      – Sean Gallagher
      Aug 20 at 13:56










    • No, you have to perform multiple queries.
      – Doug Stevenson
      Aug 20 at 13:58










    • And to add to this is there any way to write queries within other queries
      – Sean Gallagher
      Aug 20 at 14:22
















    • Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
      – Sean Gallagher
      Aug 20 at 13:16










    • As I said, write multiple queries to get the data you need.
      – Doug Stevenson
      Aug 20 at 13:20










    • is there anyway to write a function within a query to retrieve data maybe.
      – Sean Gallagher
      Aug 20 at 13:56










    • No, you have to perform multiple queries.
      – Doug Stevenson
      Aug 20 at 13:58










    • And to add to this is there any way to write queries within other queries
      – Sean Gallagher
      Aug 20 at 14:22















    Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
    – Sean Gallagher
    Aug 20 at 13:16




    Is there anyway at all to query within a query even to try and retrieve this data and make a connection between the two collections.
    – Sean Gallagher
    Aug 20 at 13:16












    As I said, write multiple queries to get the data you need.
    – Doug Stevenson
    Aug 20 at 13:20




    As I said, write multiple queries to get the data you need.
    – Doug Stevenson
    Aug 20 at 13:20












    is there anyway to write a function within a query to retrieve data maybe.
    – Sean Gallagher
    Aug 20 at 13:56




    is there anyway to write a function within a query to retrieve data maybe.
    – Sean Gallagher
    Aug 20 at 13:56












    No, you have to perform multiple queries.
    – Doug Stevenson
    Aug 20 at 13:58




    No, you have to perform multiple queries.
    – Doug Stevenson
    Aug 20 at 13:58












    And to add to this is there any way to write queries within other queries
    – Sean Gallagher
    Aug 20 at 14:22




    And to add to this is there any way to write queries within other queries
    – Sean Gallagher
    Aug 20 at 14:22












    up vote
    0
    down vote













    According to multiple Google Firebase engineers, querying across collections is not at all possible, despite the Firestore documentation that says:




    If you need to query data across collections, use
    root-level collections.




    https://firebase.google.com/docs/firestore/data-model?authuser=3



    I would suggest that Google rewrite this part of their documentation because that sentences literally infers the opposite. It should read along the lines of:




    If you need to query data across collections, not happening.







    share|improve this answer
























      up vote
      0
      down vote













      According to multiple Google Firebase engineers, querying across collections is not at all possible, despite the Firestore documentation that says:




      If you need to query data across collections, use
      root-level collections.




      https://firebase.google.com/docs/firestore/data-model?authuser=3



      I would suggest that Google rewrite this part of their documentation because that sentences literally infers the opposite. It should read along the lines of:




      If you need to query data across collections, not happening.







      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        According to multiple Google Firebase engineers, querying across collections is not at all possible, despite the Firestore documentation that says:




        If you need to query data across collections, use
        root-level collections.




        https://firebase.google.com/docs/firestore/data-model?authuser=3



        I would suggest that Google rewrite this part of their documentation because that sentences literally infers the opposite. It should read along the lines of:




        If you need to query data across collections, not happening.







        share|improve this answer












        According to multiple Google Firebase engineers, querying across collections is not at all possible, despite the Firestore documentation that says:




        If you need to query data across collections, use
        root-level collections.




        https://firebase.google.com/docs/firestore/data-model?authuser=3



        I would suggest that Google rewrite this part of their documentation because that sentences literally infers the opposite. It should read along the lines of:




        If you need to query data across collections, not happening.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 1:31









        narddog

        1,764620




        1,764620



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51930931%2ftrying-to-query-across-collections-in-google-firestore%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            天津地下鉄3号線

            How to fill missing numeric if any value in a subset is missing, all other columns with the same subset are missing