查询大量文档是否会导致读取集合中的所有文档,即使它们不满足条件?

Will a query of a big number of docs cause a read on all the doc in the collection even if they don't meet the condition?

基本上,我想查询可能包含 100 个文档或 200.000 个文档的数据集合。 由于我想在一个查询中定位,假设最多 50 个,这个查询会花费我读取该集合中的文档总数还是只读取满足查询条件的文档?

    const q = query(collection(db, 'Data'), where('clientId', '==', id));

您只需为查询返回的文档数付费。如果有 50 个客户 ID 匹配的文档,无论集合中有多少文档,您都将被收取 50 次阅读费用。

您还可以 limit 从查询中返回的文档数:

const q = query(collection(db, 'Data'), where('clientId', '==', id), limit(10));

此查询将收取最多 10 次读取的费用。如果您的客户需要检索更多文档,您可以使用 startAt() 子句来获取下 10 个与查询匹配的文档。