Cost per read for Cloud Firestore

Greetings! I have come across the following code block that utilizes Angular Fire 2 to retrieve data from Cloud Firestore. While the code works well, I quickly exceeded my daily quota of 50,000 reads due to regular usage and testing.

I am curious to know whether if the result set returns a list of 200 items, Firestore counts this as 1 read or 200 reads (considering it is only one query in the code).

Furthermore, according to their quota and limits documentation, if any data in the list is modified, it is counted as an additional read. Is this applicable to all returned records or each individual record? Does this rule still apply when utilizing take(1)?

menuCol: AngularFirestoreCollection<Menu>;
menues: any;

constructor(private afs: AngularFirestore, private router : Router) { }

 ngOnInit() {
     this.menuCol = this.afs.collection('MenuItems');

        this.menues = this.menuCol.snapshotChanges().take(1)
          .map(actions => {
            return actions.map(a => {
              const data = a.payload.doc.data();
              const id = a.payload.doc.id;

              return { id, data };
            });
          });
    }

Answer №1

According to information found on the Firebase pricing page, Cloud Firestore quotas for projects under the free/Spark plan include:

Document reads: 50K/day

This quota specifically counts the number of documents that are read from Firestore on behalf of your project. For example, if a single query retrieves 200 documents, then 200 will be counted towards the daily limit.

Reviewing your current code, it can be seen that all documents are requested, only one is returned, and then the observer is detached. This means that all documents are actually being read.

If the intention is to read only one document, it is recommended to specify a limit in the observable:

 collection('MenuItems', ref => ref.limit(1))

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

Tips for validating a form in AngularJs when utilizing the ng-repeat directive

Within my AngularJS form, I successfully implemented validation for an email field. However, upon adding another email field, the validation applies to all items. My intention is for only the first field to be validated as required. <form novalidate na ...

Small preview images that open up to larger images in a modal window, with AVIF format displayed first before

On my old website, I have a collection of images displayed in thumbnail form that users can click on to view larger versions. These images are scattered throughout the page and are not the main focus. I'm looking to update this functionality by conve ...

Tips for transferring contact information from a webpage to an Android or iPhone using an HTML button and integrating JavaScript or PHP

My current project involves adding a feature to a website that allows users to save contact details from the site to their phone (Android or iPhone) with the click of an HTML button. Here's what I have done so far <!DOCTYPE html> <html lang= ...

Should you consider using the Singleton pattern in Node.js applications?

After stumbling upon this specific piece discussing the creation of a singleton in Node.js, it got me thinking. The require functionality according to the official documentation states that: Modules are cached after the first time they are loaded. Multi ...

Show segments of video stream on page using node.js

I am currently exploring Node.js and trying to understand how streams work, so please bear with me if I seem a bit unclear. After reading some beginner notes on streams, I decided to test it out. In my project files, specifically in public/images/videos/S ...

Event that signifies a change in the global state of the Angular 2 router

Is there a universal event that can be utilized for state change/start across all components, similar to the Component Lifecycle Hooks ? For example, in UI-router: $rootScope.$on("$stateChangeStart", function() {}) ...

What is the best method for displaying data on the user interface in Angular after retrieving it from a CSV file

I am currently working on implementing an Angular template where I need to display data from a CSV file in a structured table format. However, I am facing challenges with the core scripting part related to the retrieved CSV data. Here is a snippet of my c ...

The re-assignment of `req.session.variable` in Express-session does not carry over between two different routes

I am currently working on a basic app that allows logged in users to search and book train journeys using Express, MongoDB, Mongoose, and Express-session. The selected journeys are temporarily stored in the req.session.order variable (which I believe is gl ...

Determine the hour difference between two provided dates by utilizing the date-fns library

My API returns a "datePublished" timestamp like this: "2019-11-14T14:54:00.0000000Z". I am attempting to calculate the difference in hours between this timestamp and the current time using date.now() or new Date(). I am utilizing the date-fns v2 library fo ...

Using GreenSock to animate and manipulate the tween function's parameters

I have two functions that are called on mouse events: function menuBtnOver(e){ var b = e.data; b.setPosition(b.x, b.y+5); } function menuBtnOut(e){ var b = e.data; b.setPosition(b.x, b.y-5); } Additionally, there is another function: setP ...

Angular displays error ERR_UNKNOWN_URL_SCHEME when attempting to retrieve an image saved in a blob

As I transition my app from Electron to Angular, one of my main objectives is to display an image uploaded by a user. Here's how I attempted to achieve this: page.component.ts uploadImageFile(){ fileDialog({}, files =>{ //Utilizing the fileDi ...

Tips on retrieving the ID value

My goal is to access the value of the 'id' property in a component. Below is my attempt: constructor(props) { super(props); this.state = { ...

Is it feasible to maintain a variable as a reference across views while utilizing ng-view?

I am facing a unique challenge: I have a webpage with two tabs that need to utilize ng-view from AngularJS. The twist is that both tabs must share the same variable, similar to referencing a variable in C# using the "ref" keyword. If you want to see an ex ...

Can Typescript Be Integrated into an AngularJS Application?

I have been thinking about the optimal timing and scenario to implement Typescript in an AngularJS project. While I have come across examples of TS being used in a Node, Express, Mongo backend, I am particularly intrigued by how well TS integrates with A ...

Display the table upon completion of the form submission

I am trying to create a form where the table #mytable is only displayed after the form has been submitted. If nothing is entered in the form, the table should remain hidden. Any suggestions on how I can achieve this? <form action="" id="myform" method ...

Over time, memory usage increases significantly in JS applications that heavily rely on Ajax

I've noticed significant memory leaks in an app I'm currently developing. Despite its lack of complexity, the app requests approximately 40kb of JSON data from the server every 15 seconds. This data is then used to generate a table on the page. A ...

How can two functions be triggered simultaneously on a single event, one being a client-side JavaScript function and the other a server-side function

Is it possible to call two functions on the same event, one client-side and the other server-side? I need to achieve this. <input type="text" ID="txtUserName" runat="server" maxlength="50" class="DefaultTextbox" style="wid ...

Is there a way for me to retrieve the data returned from a worker thread?

In my quest to understand how worker-threads function, I've come across this useful example: https://github.com/heroku-examples/node-workers-example.git REMINDER: Ensure Redis is installed and running for this example My primary challenge lies in r ...

Tips on hiding specific table rows in two separate tables based on the chosen option from a dropdown menu

How do I hide table rows based on dropdown selection? The first table has a dropdown with two options: Current State and Future State. If I select Current State, I want to show or hide specific rows in the 2nd and 3rd tables. I am using IDs for these row ...

I am facing an issue with my react-app where it compiles successfully without any errors, but it is not rendering any elements

JavaScript file to run with npm start: import React from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter as Router } from 'react-router-dom'; import Routes from './routes'; ReactDOM.render( <R ...