The quantity of documents queried does not align with the number of data counts retrieved from Firestore

Facing an issue with calculating the Firestore read count as it keeps increasing rapidly even with only around 15 user documents. The count surges by 100 with each page reload and sometimes increases on its own without any action from me. Could this be due to a subscription behavior causing data reads to refresh periodically? (I've come across suggestions to use "once" for one-time data extraction).

Below is the TypeScript code snippet:

// All buddy users from Firebase
private usersCollection: AngularFirestoreCollection<Profile>;
users: Observable<Profile[]>;
usersFirebase: Profile[] = [];

getUserDataFromFirebase() {
this.isImageLoading = false;
this.users.subscribe(async results => {
    var ref;
    for(let result of results) {
      if(result.imageName) {
        ref = this.store.ref('images/' + result.userId + '/profiles/' + result.imageName);
      } else {
        // Get default image if image does not exist.
        ref = this.store.ref('images/ironman.jpg');
      }

      await ref.getDownloadURL().toPromise().then(urlString => {
        result.profileURL = urlString;
        // Convert availability date from timestamp to date format
        try {
          result.availability = this.datePipe.transform(result.availability.toDate(), 'yyyy-MM-dd');
        } catch (error) {}
        result.flip = 'inactive';

        if(result.identity == 'Tenant')
        {
          this.usersFirebase.push(result);
        }
        return new Promise((resolve, reject) => {
            resolve();
          })
      });
    }
    console.log(this.usersFirebase);
  });
}

How exactly does the firestore read count function? Is the increment based on document queries and does it continue querying itself after a certain period? Firestore read count exceeds number of user documents

Answer №1

The focus of read counts is on the number of documents retrieved.

Let's consider these four scenarios:

  • If you have a collection of 10 users and you execute a collection("users").get() call, you will receive 10 employee documents and incur 10 reads.
  • Having a collection of 10,000 users and running a collection("users").get() call will result in retrieving 10,000 users and being charged for 10,000 reads.
  • For a collection of 10,000 employees, using
    collection("users").get().limit(10)
    will give you 10 users and cost you 10 reads.
  • In a collection of 10,000 users with 15 named "Carl," executing
    collection("users").where("first_name", "==", "Carl")
    will return 4 users and require 15 reads.

Conversely, if you are monitoring the entire collection users without any where() or orderBy() clauses and have an active onSnapshot() listener, you will be billed for a document read operation each time a new document is added, changed, or deleted in the collection users.

It may be worth reviewing your workflow to ensure that other processes aren't impacting the read operations in your collection.

Furthermore, keep in mind that the reported read ops may not align perfectly with billing and quota usage. There is a feature request related to this issue in the Public Issue Tracker regarding reads on Firestore: here. You can "star" it and adjust the notifications to stay updated. Additionally, feel free to create a new issue if needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue deploying Angular 2 and Rails 5 on Heroku: npm command not found in bash

After successfully deploying an Angular2 on Rails5 app to Heroku and setting up the PG database, I encountered a stack trace in the Heroku app log indicating that the npm command was not found. This error has been perplexing as I try to troubleshoot the is ...

What is the best way to search and sort a MatTable with special characters like accents and diacrit

I need to implement a name filtering functionality for a table, regardless of whether the user includes accents or not. For instance: If the user types "hydrogen", the result should display "Hydrôgen" from the table. I am using Angular 8.1.3 and Angula ...

Jest's it.each method is throwing an error: "This expression is not callable. Type 'String' has no call signatures."

I've been attempting to utilize the describe.eachtable feature with TypeScript, but I keep running into an error message stating: "error TS2349: This expression is not callable. Type 'String' has no call signatures." Below is my code snippe ...

Imitate a targeted ngxs store selection using ngxs

Within this component, there are two ngxs selectors being utilized: @Component({ selector: 'some-component', templateUrl: './some-component.html', styleUrls: ['./some-component.scss'], changeDetection: ChangeDetectionS ...

Arrange the items in the last row of the flex layout with equal spacing between them

How can I arrange items in rows with equal space between them, without a large gap in the last row? <div fxFlex="row wrap" fxLayoutAlign="space-around"> <my-item *ngFor="let item of items"></my-item> </div> Current Issue: htt ...

Struggling to Retrieve Specific Keys for Individual Values in Firebase with React Native

I am currently experiencing difficulty obtaining a unique key for each value in the 'users1' table. firebase.database().ref('users1').once('value').then(snapshot => { var items = []; snapshot.forEach((child) => { ...

Creating folders and writing data to text files in Angular 4/5 with TypeScript: A tutorial

Is it feasible to create a folder, text file, and write data into that file in Angular5 using Typescript for the purpose of logging errors? Your expertise on this matter would be greatly appreciated. Thank you in advance! ...

The error message "Can't resolve all parameters for CustomerService" is preventing Angular from injecting HttpClient

I have a customerService where I am attempting to inject httpClient. The error occurs on the line where I commented //error happens on this line. Everything works fine until I try to inject httpClient into my service. The error message is: `compiler.js: ...

After introducing 5 guard properties, the intersection of unions in Typescript breaks down

In TypeScript, I am attempting to create a class where properties are only accessible if another property has been checked on the class. This needs to be done in a generic manner to facilitate reuse across multiple classes. For instance, class Test { Fo ...

Enhancing Application Performance Through Next.js Development

I'm currently working on an application using next.js and I am looking to implement code splitting in order to reduce the bundle size and load pages on demand. Unfortunately, I have not been able to find a way to do this without specifying routes. Fo ...

Creating Dynamic HTML/DOM in Angular 14: A Guide for Adding New Items to a List

I am currently iterating through a list of items and displaying them within a div element. These items are rendered when the page initially loads. <button (click)="addCut()" mat-raised-button color="primary">Add New Cut</button ...

Issue: Custom Object is returning an error stating that the property 'forEach' does not exist on type 'void'.ts(2339)

Within my code, I am dealing with a variable that can be either of type User or void. The dilemma arises when the code runs into an error message saying: Property 'forEach' does not exist on type 'void'.ts(2339). Despite trying various ...

Display the spinner until the data is successfully updated in the DOM using Angular

Dealing with a large dataset displayed in a table (5000 rows), I am attempting to filter the data using column filters. When applying the filter, I have included a spinner to indicate that the filtering operation is in progress. However, due to the quick ...

limiting the number of HTTP requests within a JavaScript forEach loop

In my current coding situation, I am facing an issue where the HTTP requests are being made simultaneously within a forEach loop. This leads to all the requests firing off at once. const main = async () => { items.forEach(async (i: Item) => ...

Angular: monitoring changes in HTML content within a Component or Directive

I have a situation where I am retrieving HTML content from a REST endpoint using a directive and inserting it into a div element using [innerHTML]. Once this HTML content is rendered, I would like to manipulate it by calling a global function. My approach ...

"Resulting in 'undefined' due to an asynchronous function call

Encountering an issue with async method implementation. In my authServices, there is a loginWithCredential function which is asynchronous: async loginWithCredential(username, password){ var data = {username: username, password: password}; api.pos ...

The tooltip is obscured by the table row

I'm having trouble with a simple CSS fix and can't seem to figure out why. The z-index and overflow visibility properties are not working as expected. I just need 'In Progress' to be displayed above everything else. Some things I' ...

What are the best techniques for centering a prime ng form both vertically and horizontally?

I am currently using prime ng 9.1.3 along with primeflex 1.3.0 in my project. Despite applying p-align-center, I am facing difficulty in vertically and horizontally centering the form on the screen when using a full screen height of 100vh. <div class=&q ...

Tips on updating primeng Panel Menu appearance with scss

I'm looking to customize the color of my panel menu to black. Below is the HTML code I am using. <p-panelMenu styleClass="font-bold text-xs m-0 w-11" [model]="items" [multiple]='false'></p-panelMenu> ...

Running an Angular 2 application locally without using Node? Here's how you can do

After completing a tutorial on creating a movie finder app using Angular 2, I found that the project could only be viewed by running 'npm start' in command line. Is there a way to allow others to view my project locally on their machines even if ...