Home > Back-end >  Firestore - Am I charged for documents obtained without finishing reading their data?
Firestore - Am I charged for documents obtained without finishing reading their data?

Time:06-06

Imagine you perform a query and retrieve 1000 docs from the database.

const querySnapshot = await query.get();

If I do not execute the .data() method of each doc to read their data, would it still be treated as 1000 reads?

CodePudding user response:

Yes, the get() retrieves documents from Firestore and you'll be charged N reads where N is number of documents returned by your query. The .data() just returns the document's data in JSON format from the snapshots.

Do note that, just creating the query neither retrieves the data nor charges you anything.

// 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())
  • Related