Is there a method to iterate through all documents

2019-07-02 20:16发布

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
})

1条回答
劫难
2楼-- · 2019-07-02 20:29

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: Query.get()

iOS/Swift: Query.getDocuments()

JavaScript: Query.get()

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

See also the product documentation for "Get all documents in a collection".

查看更多
登录 后发表回答