Brent Parker
Brent Parker

Reputation: 739

Firebase Firestore get() counts as 3 api calls

I've been working on a simple app this week to learn to use Firestore and I've been watching my api calls on the quotas page. All week I had barely used 400 calls but suddenly today the reporting shot up over 50,000. Now, my Firestore only has 2 collections, and one collection only has 8 documents in it. So there's not a lot of data. My app is still very primitive and can only either collection, and add/update documents in only one of those. I mention all that to explain that my app does not do much, so it was very surprising when I saw the usage.

I started digging into the individual calls and noticed that when I perform a single call:

let db = fire.firestore();
db.collection("tags").get()
.then( snapshot => {
  console.log(snapshot);
})
.catch( error => {
  console.log(error);
})

the Cloud Firestore API Calls counter increased by 3. There are no custom functions, no database rules other than

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if request.auth.uid != null;
      allow write: if request.auth.uid != null;
    }
  }
}

I haven't looked at creating/updating documents yet, but would anyone know why this one get() would count as 3 api calls?

Upvotes: 0

Views: 1190

Answers (2)

Will Ullrich
Will Ullrich

Reputation: 2228

Disclaimer:

I am NOT suggesting this solves your issue of reaching 50,000+ API calls, however I am suggesting this will most likely be an issue you have within that quota.


Viewing & editing your project's data through Firestore's console will count towards your overall Cloud Firestore API Calls quota.

Again you may not find this helpful, but more times than not users will test their application (whether it be running an auth, writing a new value for a field, or a cloud function) while watching the data change. This will result in inconsistent quota increases as you are essentially reading / writing in two places at once.

I recommend trying this through observation of the app only with log statements best describing the processes occurring. If you are still seeing strange quota increases, unfortunately it resides in your code, not with Google. Hope this helps!

Upvotes: 3

Ashish Yadav
Ashish Yadav

Reputation: 543

If in case security rule is the reason, just try with the following Security rule until the app is in the development process:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

Upvotes: 1

Related Questions