是否有一种方法可以遍历Firestore中集合中的所有文档

问题描述:

我正在使用Firebase的Firestore,并且想遍历整个集合.是否有类似的东西:

I'm using the firestore of firebase and I want to iterate through the whole collection. Is there something like:

db.collection('something').forEach((doc) => {
  // do something
})

是的,您可以使用集合引用上的get()方法简单地查询集合的所有文档. CollectionReference对象是Query的子类,因此您可以在其上调用Query方法.就其本身而言,集合引用实质上是对其所有文档的未经过滤的查询.

Yes, you can simply query the collection for all its documents using the get() method on the collection reference. A CollectionReference object subclasses Query, so you can call Query methods on it. By itself, a collection reference is essentially an unfiltered query for all of its documents.

Android:查询. get()

iOS/Swift: Query.getDocuments( )

iOS/Swift: Query.getDocuments()

JavaScript: Query.get()

JavaScript: Query.get()

在每个平台中,此方法都是异步的,因此您必须正确处理回调.

In each platform, this method is asynchronous, so you'll have to deal with the callbacks correctly.

另请参见"在集合".