Is there a method to iterate through all documents in a collection in firestore

前端 未结 2 1462
小蘑菇
小蘑菇 2021-02-20 01:45

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


        
2条回答
  •  一整个雨季
    2021-02-20 02:20

    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".

提交回复
热议问题