Reputation: 854
I have datas on realtime Database on firebase with the following structure :
{ "tests" : [ {
"description" : "55",
"number" : "11",
"serie" : "0" }, {
"description" : "22",
"number" : "13",
"serie" : "0" }, {
"description" : "Test",
"number" : "55",
"serie" : "2"
} ]
And I want tro retrieve all my data where the field "serie" are equal to "0". I have a methode in my service component for retrieving all the tests data, like this :
getTests(){
firebase.database().ref('/tests')
.on('value',(data: DataSnapshot)=>{
this.tests= data.val() ? data.val():[];
this.emitTests;
}
);
}
At this time I do not know how retrieving only datas where serie is equal to 0.
Upvotes: 1
Views: 1845
Reputation: 599776
You do that by using a Firebase Database query:
firebase.database().ref('/tests')
.orderByChild("serie").equalTo("0")
.on('value',(data: DataSnapshot) => {
data.forEach((child: DataSnapshot) => {
console.log(child.key, child.val());
});
As you can see a query in Firebase has two steps:
Also see the Firebase documentation on ordering and filtering data.
Upvotes: 2