-4

The following code as an example, I am confused about after which numbered line I will be charged for reads in the query result.

I do I understand the info mentioned in this stackoverflow answer, I feel lost in something and I would appreciate some guidance in this.

docRef
  .collection('comments')
  .orderBy('createdAt', 'desc')
  .get() // #1 <---------
  .then(querySnapshot => { // #2 <---------

    const commentCount = querySnapshot.size // #3 <---------

    const recentComments = []

    querySnapshot.forEach(doc => { // #4 <---------
      recentComments.push( doc.data() )
    });

    recentComments.splice(5)

    const lastActivity = recentComments[0].createdAt

    const data = { commentCount, recentComments, lastActivity }

    return docRef.update(data)
    })

  .catch(err => console.log(err) )
Ahmed Shendy
  • 1,424
  • 15
  • 28

1 Answers1

2

The client retrieves the documents when you call get(), so that is when you'll be charged for the documents read and the bandwidth used.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807