How to read data reference in a document firestore -flutter












-2















I'm developing an app with Firestore. I want to read the data of document A referenced from document B and get the fields I set in document B. I searched but can't seem to find a solution. Any help would be greatly appreciated.










share|improve this question

























  • Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

    – Xar E Ahmer
    Nov 14 '18 at 6:09











  • I would shown code if I know how to

    – Folarin Opeyemi
    Nov 14 '18 at 9:01











  • Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

    – Folarin Opeyemi
    Nov 14 '18 at 9:02













  • You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

    – Xar E Ahmer
    Nov 14 '18 at 10:59













  • Call two services, as in two streambuilder?

    – Folarin Opeyemi
    Nov 14 '18 at 11:02
















-2















I'm developing an app with Firestore. I want to read the data of document A referenced from document B and get the fields I set in document B. I searched but can't seem to find a solution. Any help would be greatly appreciated.










share|improve this question

























  • Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

    – Xar E Ahmer
    Nov 14 '18 at 6:09











  • I would shown code if I know how to

    – Folarin Opeyemi
    Nov 14 '18 at 9:01











  • Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

    – Folarin Opeyemi
    Nov 14 '18 at 9:02













  • You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

    – Xar E Ahmer
    Nov 14 '18 at 10:59













  • Call two services, as in two streambuilder?

    – Folarin Opeyemi
    Nov 14 '18 at 11:02














-2












-2








-2








I'm developing an app with Firestore. I want to read the data of document A referenced from document B and get the fields I set in document B. I searched but can't seem to find a solution. Any help would be greatly appreciated.










share|improve this question
















I'm developing an app with Firestore. I want to read the data of document A referenced from document B and get the fields I set in document B. I searched but can't seem to find a solution. Any help would be greatly appreciated.







android dart flutter google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 1:26









dchi

212




212










asked Nov 13 '18 at 22:12









Folarin OpeyemiFolarin Opeyemi

62




62













  • Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

    – Xar E Ahmer
    Nov 14 '18 at 6:09











  • I would shown code if I know how to

    – Folarin Opeyemi
    Nov 14 '18 at 9:01











  • Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

    – Folarin Opeyemi
    Nov 14 '18 at 9:02













  • You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

    – Xar E Ahmer
    Nov 14 '18 at 10:59













  • Call two services, as in two streambuilder?

    – Folarin Opeyemi
    Nov 14 '18 at 11:02



















  • Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

    – Xar E Ahmer
    Nov 14 '18 at 6:09











  • I would shown code if I know how to

    – Folarin Opeyemi
    Nov 14 '18 at 9:01











  • Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

    – Folarin Opeyemi
    Nov 14 '18 at 9:02













  • You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

    – Xar E Ahmer
    Nov 14 '18 at 10:59













  • Call two services, as in two streambuilder?

    – Folarin Opeyemi
    Nov 14 '18 at 11:02

















Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

– Xar E Ahmer
Nov 14 '18 at 6:09





Kindly show some code or explain it in detail. What attribute document has and on what basis (it's id or any attribute) you wanna fetch data.

– Xar E Ahmer
Nov 14 '18 at 6:09













I would shown code if I know how to

– Folarin Opeyemi
Nov 14 '18 at 9:01





I would shown code if I know how to

– Folarin Opeyemi
Nov 14 '18 at 9:01













Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

– Folarin Opeyemi
Nov 14 '18 at 9:02







Doc A has fields in it stored as string data type. Doc B has a data type Ref, referencing to Doc A. What I want is get the fields stored in Doc A through Doc B.

– Folarin Opeyemi
Nov 14 '18 at 9:02















You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

– Xar E Ahmer
Nov 14 '18 at 10:59







You have to call two services first to get the parameter. First call is to get the reference type and then call service again with orderBy filter on that reference and limit to 1 to get only single record

– Xar E Ahmer
Nov 14 '18 at 10:59















Call two services, as in two streambuilder?

– Folarin Opeyemi
Nov 14 '18 at 11:02





Call two services, as in two streambuilder?

– Folarin Opeyemi
Nov 14 '18 at 11:02












1 Answer
1






active

oldest

votes


















0














you can get ref_value like this



await Firestore.instance
.collection('collection')
.where('ref', isEqualTo: 'what you want to query')
.getDocuments()
.then((doc) {
ref_value = doc.documents[0]['ref'];
});


get another with that reference



await Firestore.instance
.collection('collection')
.where('ref', isEqualTo: ref_value)
.limit(1)
.getDocuments()
.then((doc) {
ref_value = doc.documents[0]['ref'];
});


this code may help you try out things further..






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',
    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%2f53290285%2fhow-to-read-data-reference-in-a-document-firestore-flutter%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














    you can get ref_value like this



    await Firestore.instance
    .collection('collection')
    .where('ref', isEqualTo: 'what you want to query')
    .getDocuments()
    .then((doc) {
    ref_value = doc.documents[0]['ref'];
    });


    get another with that reference



    await Firestore.instance
    .collection('collection')
    .where('ref', isEqualTo: ref_value)
    .limit(1)
    .getDocuments()
    .then((doc) {
    ref_value = doc.documents[0]['ref'];
    });


    this code may help you try out things further..






    share|improve this answer




























      0














      you can get ref_value like this



      await Firestore.instance
      .collection('collection')
      .where('ref', isEqualTo: 'what you want to query')
      .getDocuments()
      .then((doc) {
      ref_value = doc.documents[0]['ref'];
      });


      get another with that reference



      await Firestore.instance
      .collection('collection')
      .where('ref', isEqualTo: ref_value)
      .limit(1)
      .getDocuments()
      .then((doc) {
      ref_value = doc.documents[0]['ref'];
      });


      this code may help you try out things further..






      share|improve this answer


























        0












        0








        0







        you can get ref_value like this



        await Firestore.instance
        .collection('collection')
        .where('ref', isEqualTo: 'what you want to query')
        .getDocuments()
        .then((doc) {
        ref_value = doc.documents[0]['ref'];
        });


        get another with that reference



        await Firestore.instance
        .collection('collection')
        .where('ref', isEqualTo: ref_value)
        .limit(1)
        .getDocuments()
        .then((doc) {
        ref_value = doc.documents[0]['ref'];
        });


        this code may help you try out things further..






        share|improve this answer













        you can get ref_value like this



        await Firestore.instance
        .collection('collection')
        .where('ref', isEqualTo: 'what you want to query')
        .getDocuments()
        .then((doc) {
        ref_value = doc.documents[0]['ref'];
        });


        get another with that reference



        await Firestore.instance
        .collection('collection')
        .where('ref', isEqualTo: ref_value)
        .limit(1)
        .getDocuments()
        .then((doc) {
        ref_value = doc.documents[0]['ref'];
        });


        this code may help you try out things further..







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 9:48









        UpaJahUpaJah

        691312




        691312






























            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%2f53290285%2fhow-to-read-data-reference-in-a-document-firestore-flutter%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