是否有一种方法可以遍历Firestore中集合中的所有文档 [英] Is there a method to iterate through all documents in a collection in firestore

查看:87
本文介绍了是否有一种方法可以遍历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.

另请参见"在集合".

这篇关于是否有一种方法可以遍历Firestore中集合中的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆