Harry Wega
Harry Wega

Reputation: 45

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?

Upvotes: 3

Views: 742

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222722

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.

Upvotes: 5

Related Questions