Ionic 我可以在firestore中获取集合中文档的id列表而不生成读操作吗?[duplicate]

iq0todco  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(127)

This question already has answers here:

Get only collection IDs from Cloud Firestore in one read count (4 answers)
How to get a list of document IDs in a collection Cloud Firestore? (3 answers)
Closed 4 months ago.
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))
       );
  }
gmol1639

gmol16391#

不,不可能在不产生读取成本的情况下从Firestore中获取任何文档信息。读取成本包括使用保存文档ID的索引--使用索引时,每读取一个与查询匹配的文档将收取一次费用。您现在显示的代码将每读取“products”集合中的一个文档收取一次费用。

相关问题