Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Collection in AngularFirestore results in no data when using "where()"

I have a list on firebase of locations in several towns. The access works with:

 public locations: Observable<any[]>;
 constructor(db: AngularFirestore) {
 this.locations = db.collection('/Locations').valueChanges();}

Then I can access the data of all locations with:

 {{ location.location_id }} etc

Now I want to access all locations in one specific town in the next page.

this.locationCollection = db.collection('/Locations', ref =>
ref.where('location_id', '==', 'Townname'));

But it is not assignable or _scalar. If I change locationCollection to AngularFirestoreCollection then I get no error but also no data. If I change the class location to an interface it is also the same. I even tried to get

this.location = db.doc('/Locations/' + townname);

But I cannot access the attributes or log the request to console. I feel like I have wasted my time with too many obsolete tutorials. Could anyone point me into the right direction or does anyone have the angular heroes example with the MOST RECENT firebase setup?

like image 593
Harry Wega Avatar asked Dec 05 '25 22:12

Harry Wega


1 Answers

Try this way

this.locationCollection = this.db.collection('Locations', ref => ref.where('location_id', '==', 'Townname')

and define it as,

 locations: Array<any>;
 locationCollection: AngularFirestoreCollection<Location>;

where Location is the model.

like image 117
Sajeetharan Avatar answered Dec 08 '25 12:12

Sajeetharan