How to read data reference in a document firestore -flutter
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
|
show 2 more comments
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
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
|
show 2 more comments
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
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
android dart flutter google-cloud-firestore
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
|
show 2 more comments
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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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..
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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..
add a comment |
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..
add a comment |
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..
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..
answered Nov 17 '18 at 9:48
UpaJahUpaJah
691312
691312
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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