Firebase realtime database read operation - Only get part of document returned possible? [duplicate]
This question already has an answer here:
How to pull the data partially from firebase database
1 answer
I realise this question is marked as a duplicate - but I think this question is more comprehensive and easier to understand, and therefore more likely to help others. (^__^)
I have read about reading data from Firebase realtime database.
https://firebase.google.com/docs/database/admin/retrieve-data
What I have not found is any documentation on how to control what data gets returned from the read query.
Consider the following structure:
-users
-EiYu7OWooToo6noo
alias: "Kermit"
createdAt: 1538330532000
firstName: "Kermit"
surName: "Frogman"
pictureURL: "/imgs/kermit.png"
phonePrimary: "555-1234"
email: "kermit@themuppetshow.com"
-myBooks
-A1234567890
title: "Frogs 101"
...
Is there a way to tell Firebase realtime database to only return some of the document data?
This code returns the entire document:
var ref = db.ref(`users/${uid}`);
ref.once("value", (snapshot) => {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Would it be possible to only get a partial document, for example:
{
alias: "Kermit"
firstName: "Kermit"
}
My reasoning is that this would be a huge performance gain when reading large amount of data. But is it possible?
javascript firebase firebase-realtime-database
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 19:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 1 more comment
This question already has an answer here:
How to pull the data partially from firebase database
1 answer
I realise this question is marked as a duplicate - but I think this question is more comprehensive and easier to understand, and therefore more likely to help others. (^__^)
I have read about reading data from Firebase realtime database.
https://firebase.google.com/docs/database/admin/retrieve-data
What I have not found is any documentation on how to control what data gets returned from the read query.
Consider the following structure:
-users
-EiYu7OWooToo6noo
alias: "Kermit"
createdAt: 1538330532000
firstName: "Kermit"
surName: "Frogman"
pictureURL: "/imgs/kermit.png"
phonePrimary: "555-1234"
email: "kermit@themuppetshow.com"
-myBooks
-A1234567890
title: "Frogs 101"
...
Is there a way to tell Firebase realtime database to only return some of the document data?
This code returns the entire document:
var ref = db.ref(`users/${uid}`);
ref.once("value", (snapshot) => {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Would it be possible to only get a partial document, for example:
{
alias: "Kermit"
firstName: "Kermit"
}
My reasoning is that this would be a huge performance gain when reading large amount of data. But is it possible?
javascript firebase firebase-realtime-database
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 19:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
1
If you target this var ref = db.ref(users/${uid}/alias
); you will get only the alias
– Christophe Gudlake
Nov 13 '18 at 13:43
1
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58
|
show 1 more comment
This question already has an answer here:
How to pull the data partially from firebase database
1 answer
I realise this question is marked as a duplicate - but I think this question is more comprehensive and easier to understand, and therefore more likely to help others. (^__^)
I have read about reading data from Firebase realtime database.
https://firebase.google.com/docs/database/admin/retrieve-data
What I have not found is any documentation on how to control what data gets returned from the read query.
Consider the following structure:
-users
-EiYu7OWooToo6noo
alias: "Kermit"
createdAt: 1538330532000
firstName: "Kermit"
surName: "Frogman"
pictureURL: "/imgs/kermit.png"
phonePrimary: "555-1234"
email: "kermit@themuppetshow.com"
-myBooks
-A1234567890
title: "Frogs 101"
...
Is there a way to tell Firebase realtime database to only return some of the document data?
This code returns the entire document:
var ref = db.ref(`users/${uid}`);
ref.once("value", (snapshot) => {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Would it be possible to only get a partial document, for example:
{
alias: "Kermit"
firstName: "Kermit"
}
My reasoning is that this would be a huge performance gain when reading large amount of data. But is it possible?
javascript firebase firebase-realtime-database
This question already has an answer here:
How to pull the data partially from firebase database
1 answer
I realise this question is marked as a duplicate - but I think this question is more comprehensive and easier to understand, and therefore more likely to help others. (^__^)
I have read about reading data from Firebase realtime database.
https://firebase.google.com/docs/database/admin/retrieve-data
What I have not found is any documentation on how to control what data gets returned from the read query.
Consider the following structure:
-users
-EiYu7OWooToo6noo
alias: "Kermit"
createdAt: 1538330532000
firstName: "Kermit"
surName: "Frogman"
pictureURL: "/imgs/kermit.png"
phonePrimary: "555-1234"
email: "kermit@themuppetshow.com"
-myBooks
-A1234567890
title: "Frogs 101"
...
Is there a way to tell Firebase realtime database to only return some of the document data?
This code returns the entire document:
var ref = db.ref(`users/${uid}`);
ref.once("value", (snapshot) => {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Would it be possible to only get a partial document, for example:
{
alias: "Kermit"
firstName: "Kermit"
}
My reasoning is that this would be a huge performance gain when reading large amount of data. But is it possible?
This question already has an answer here:
How to pull the data partially from firebase database
1 answer
javascript firebase firebase-realtime-database
javascript firebase firebase-realtime-database
edited Nov 18 '18 at 19:54
Kermit
asked Nov 12 '18 at 18:04
KermitKermit
92114
92114
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 19:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Frank van Puffelen
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 '18 at 19:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
1
If you target this var ref = db.ref(users/${uid}/alias
); you will get only the alias
– Christophe Gudlake
Nov 13 '18 at 13:43
1
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58
|
show 1 more comment
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
1
If you target this var ref = db.ref(users/${uid}/alias
); you will get only the alias
– Christophe Gudlake
Nov 13 '18 at 13:43
1
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
1
1
If you target this var ref = db.ref(
users/${uid}/alias
); you will get only the alias– Christophe Gudlake
Nov 13 '18 at 13:43
If you target this var ref = db.ref(
users/${uid}/alias
); you will get only the alias– Christophe Gudlake
Nov 13 '18 at 13:43
1
1
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58
|
show 1 more comment
1 Answer
1
active
oldest
votes
You can't select a subset of child nodes for a query. Every query at a node always fetches the entire contents of the node - all the children and their children.
If you want only a subset of children, you have to perform different queries for each one. Alternatively, you can organize your data in such a way that commonly grouped fields are collected together at a particular node.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't select a subset of child nodes for a query. Every query at a node always fetches the entire contents of the node - all the children and their children.
If you want only a subset of children, you have to perform different queries for each one. Alternatively, you can organize your data in such a way that commonly grouped fields are collected together at a particular node.
add a comment |
You can't select a subset of child nodes for a query. Every query at a node always fetches the entire contents of the node - all the children and their children.
If you want only a subset of children, you have to perform different queries for each one. Alternatively, you can organize your data in such a way that commonly grouped fields are collected together at a particular node.
add a comment |
You can't select a subset of child nodes for a query. Every query at a node always fetches the entire contents of the node - all the children and their children.
If you want only a subset of children, you have to perform different queries for each one. Alternatively, you can organize your data in such a way that commonly grouped fields are collected together at a particular node.
You can't select a subset of child nodes for a query. Every query at a node always fetches the entire contents of the node - all the children and their children.
If you want only a subset of children, you have to perform different queries for each one. Alternatively, you can organize your data in such a way that commonly grouped fields are collected together at a particular node.
answered Nov 12 '18 at 18:26
Doug StevensonDoug Stevenson
72.4k983103
72.4k983103
add a comment |
add a comment |
console.log(snapshot.val().alias + " " + snapshot.val().firstName);
– Christophe Gudlake
Nov 12 '18 at 18:06
Yes, that would filter the result but the entire document would still be returned from the query? I edited my question to be less ambiguous. Or did you mean I can specify what parts of the document I want returned from the query?
– Kermit
Nov 13 '18 at 8:09
1
If you target this var ref = db.ref(
users/${uid}/alias
); you will get only the alias– Christophe Gudlake
Nov 13 '18 at 13:43
1
True, thanks! That would mean two requests, right? 1. ref = db.ref(users/${uid}/alias); 2. ref = db.ref(users/${uid}/firstName);
– Kermit
Nov 13 '18 at 16:49
yes but i'm not sure you will gain in performance with that.
– Christophe Gudlake
Nov 13 '18 at 16:58