Search code examples
firebaseionic-frameworkgoogle-cloud-firestoreangularfire

Get only collection IDs from Cloud Firestore in one read count


In this document of Cloud Foreshore it is mentioned that 'a request for a list of collection IDs, you are billed for one document read.'

Now I am using AngularFire and Ionic3 for my project. My requirement is to fetch just the collection IDs from a collection with a where condition. If I do the following, it will cost me the number of reads = number of docs in the result.

let snap = this.afs.collection('path').ref
        .where('field', "==",'data').get();

snap.forEach(x => {
          list.push(x.id);
        });

I am not able to use method getCollections() which I found in a few places as a solution.

Please let me know if you have a solution.


Solution

  • It sounds like you are wondering if there is a way to get all the document IDs in a collection without incurring a read for each document. This is currently not possible. When using Firestore client SDKs, your only option is to query the entire collection, which will transfer the entire contents of every document to the client.