Angularfire: Missleading doc information about querying

Created on 27 Oct 2017  路  2Comments  路  Source: angular/angularfire

Version info

Angular: 4.4.3

Firebase: 4.6.0

AngularFire: 5.0.0-rc.3

Other (e.g. Ionic/Cordova, Node, browser, operating system):

Ionic-angular: 3.7.1

How to reproduce these conditions

Steps to set up and reproduce

  • Setup a new firestore database with a collection and a subcollection
  • Try to query the subcollection using the docs example

The doc at https://github.com/angular/angularfire2/blob/master/docs/firestore/querying-collections.md shows an example, which is:

// WARNING: Do not copy and paste. This will not work! ref.where('tags.awesome', '==', true).orderBy('population')

But the reason for it no to work, as stated by the docs is that "Range filters / orderBy cannot be used in conjunction with user-defined data, they require composite indexes be defined on the specific fields."
This lead me to thinking that I could query subcollections because the tags.awesome made me belive that 'tags' is a subcollection of whatever collection you're querying and 'awesome' is a property of said collection. This is the code that I used for testing:

let ordersWithOffersCollection = this.afs.collection('orders', ref => ref.where('offers.price', '==', 150)); return ordersWithOffersCollection.snapshotChanges() .map(actions => { return actions.map(a => { const data = a.payload.doc.data(); return data; }); });
I have a order collection with a offer subcollection, the result that I get from logging the return of the function is this:

image

Oh, and I do have an offer document with a price equal to 150. And this is the code used to log:

let x = this.orderService.getOrdersWithMyOffers(); x.subscribe(val => { console.log(val); })

Either my code is wrong or the docs have a weird information.

Any ideas?

Most helpful comment

Tags in this case is an map type, rather than a subcollection. .awesome being dynamic user-defined data, which is not indexed. I pulled this section straight from the Firestore documentation here https://firebase.google.com/docs/firestore/solutions/arrays

They seemed to have cleaned up the language since. I'll pull in their changes.

All 2 comments

Tags in this case is an map type, rather than a subcollection. .awesome being dynamic user-defined data, which is not indexed. I pulled this section straight from the Firestore documentation here https://firebase.google.com/docs/firestore/solutions/arrays

They seemed to have cleaned up the language since. I'll pull in their changes.

haha very interesting, but is that issue is no more issue? can we close? 馃ぃ @guilhermehto

Was this page helpful?
0 / 5 - 0 ratings