最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to "Get all documents in a collection" in Firestore? - Stack Overflow

programmeradmin0浏览0评论

I saw the example code which "Get all documents in a collection" from the doc.

import { collection, getDocs } from "firebase/firestore";

const querySnapshot = await getDocs(collection(db, "cities"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});

But I'm wondering if this really will get all the documents from the collection.

I've used DynamoDB before, in DynamoDB you can't just get all the items in a table at once, to get all the items in a table you have to paginate(send multiple requests) if the data set is too large. For example if the size of all the items is 10MB, you have to send 10 requests to get all the items.

I'm wondering if this limit also applies to Firestore? Can I really get all the data of a collection in just one request even if the size was like 1GB?

I saw the example code which "Get all documents in a collection" from the doc.

import { collection, getDocs } from "firebase/firestore";

const querySnapshot = await getDocs(collection(db, "cities"));
querySnapshot.forEach((doc) => {
  // doc.data() is never undefined for query doc snapshots
  console.log(doc.id, " => ", doc.data());
});

But I'm wondering if this really will get all the documents from the collection.

I've used DynamoDB before, in DynamoDB you can't just get all the items in a table at once, to get all the items in a table you have to paginate(send multiple requests) if the data set is too large. For example if the size of all the items is 10MB, you have to send 10 requests to get all the items.

I'm wondering if this limit also applies to Firestore? Can I really get all the data of a collection in just one request even if the size was like 1GB?

Share Improve this question edited Jan 15, 2022 at 4:48 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges Recognized by Google Cloud Collective asked Jan 15, 2022 at 2:05 yaquawayaquawa 7,33812 gold badges41 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

I'm wondering if this really will get all the documents from the collection.

Yes it will. That's in fact precisely why that code sample is in the documentation on getting all documents in a collection.

If you think this number of documents may grow beyond what the connection or device can handle, you limit the maximum number of documents that are retrieved. If you want to then show more documents optionally, you can implement cursor-based pagination.

发布评论

评论列表(0)

  1. 暂无评论