Reputation: 145
Right now I'm trying to use query like this:
this.topNews = this.af.database.list('news',{
query: {
orderByChild: 'label/sport',
equalTo: 'true'
}
});
Unfortunately I don't really get anything... I thought it is possible to query by a child's child.. and I still hope it is!
My structure:
news
-new1
-content...
-labels
-sport : true
-soccer: true
-new2
...
Thanks!
Addotional question: is it possible to get - somehow every label type (like sport,soccer..) from the database, or is it any good practice to be able to collect/and then filter by them? I will add the labels dynamically to the news and then somehow be able to query by all of them... (I have experience with SQL and I still can't fully understand the logic behind this noSQL)
Upvotes: 1
Views: 611
Reputation: 145
I realized after a few try that in the firebase when you write true it actually includes a true bool value, not a 'true' string, so right now it is working this way:
this.topNews = this.af.database.list('news',{
query: {
orderByChild: 'labels/sport',
equalTo: true //this changed!
}
});
Upvotes: 2
Reputation: 5525
It is not a full answer, just a guess. Try to change to this:
this.topNews = this.af.database.list('news',{
query: {
orderByChild: 'labels/sport',
equalTo: 'true'
}
});
or
this.topNews = this.af.database.list('news',{
query: {
orderByChild: 'label',
equalTo: 'sport'
}
});
About the structure part, I think you should maintain a separated collection that holds the labels this way you can access it faster. There is no problem in duplicating things in noSQL. The only thing you should pay attention is that when you change this label in the labels table, you must update every document that uses it so you won't end up with inconsistency.
Upvotes: 1