0

I have an ionic project and use firestore services

Ionic:

Ionic CLI : 6.19.0 (C:\Users\Windows 10\AppData\Roaming\npm\node_modules@ionic\cli) Ionic Framework
: @ionic/angular 6.0.14 @angular-devkit/build-angular : 13.3.1
@angular-devkit/schematics : 13.3.1 @angular/cli
: 13.3.1 @ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.4.3 @capacitor/android : 3.4.3
@capacitor/core : 2.4.5 @capacitor/ios : not installed

Utility:

cordova-res : 0.15.4 native-run : 1.5.0

System:

NodeJS : v16.14.2 (C:\Program Files\nodejs\node.exe) npm : 8.5.0 OS : Windows 10

Is there a way to get the list of ids of the documents that belong to a collection without generating a read operation?

example

constructor(
    private afs: AngularFirestore,
  ) { 
    afs.collection<Pais>('products').ref.onSnapshot( 
         products => products.forEach(product => console.log(product.id))
       );
  }

1 Answers1

1

No, it is not possible to get any document information out of Firestore without incurring the cost of a read. The cost of a read covers the use of the index that holds the document IDs - any use of an index will be billed one read per document matching a query. The code you are showing right now will be billed one read for each document in the "products" collection.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441