假设您执行一个查询并从数据库中检索1000个文档。
const querySnapshot = await query.get();
如果我不执行每个doc的.data()
方法来读取它们的数据,它仍然会被视为1000次读取吗?
是的,get()
从Firestore检索文档,您将被收取N次读取,其中N是您的查询返回的文档数量。.data()
仅从快照中以JSON格式返回文档的数据。
请注意,仅仅创建query
既不检索数据也不收取任何费用。
// This is just a Query
const query = db.collection('').where(...);
// QuerySnapshot - contains the documents matching your query.
// fetches from Firestore (unless you have any offline persistence)
const querySnapshot = await query.get();
// Array of objects - parsed from the querySnapshot
const data = querySnapshot.docs.map((d) => d.data())