Hello,
I am attempting to get a list of document IDs from firebase, but do not want to be billed for each document read.
Is there a way to use the Firebase Admin integration to do more than just manage and list Firebase users? (such as to list document ids?)
The reason I am trying to use the Firebase Admin api to get a list of document IDs is because that is one way to access them without being hit with a per-document-retrieval charge, AND it also returns only the ID (not the full document object).
To put this more clearly, in the words of one helpfuls stackoverflow contributor:
[In a firebase query] You'll be billed on one read per document retrieved. There is no way of being billed only once for this [kind of] operation.
As people have mentioned in other answer[s], this is not possible on the client firebase SDK. But this is possible using the
firebase-admin
from your server code.This is how you can do it:
admin.initializeApp(config); const querySnapshot = await admin.firestore().collection("YOUR_COLLECTION").select().get(); for (const docSnapshot of querySnapshot.docs) { console.log(docSnapshot.id); // THIS WILL PRINT THE DOC ID console.log(docSnapshot.data()); // THIS WILL PRINT EMPTY OBJECT {} }
You can see that
docSnapshot.data()
prints{}
because no document data was retrieved, other than the document reference insidedocSnapshot
.
(quote from CBDeveloper on Dec 2, 2020, firebase - Get only collection IDs from Cloud Firestore in one read count - Stack Overflow)
Other Referenced Reading:
- Retool Docs for Custom API Authentication
This one seems promising as it seems I can manually configure retool via manually coding the authentication and connection ... but a bit too much heavy lifting for my experience level (https://docs.retool.com/docs/custom-api-authentication) - Retool Forum- ability to use custom JS Code for Firebase Admin SDK
... title seemed promissing, but forum was dead. (Use Admin Firebase SDK in the custom JS code?) - Google Firebase Documentation regarding the ability to limit data retrieved from firebase
Catch is that this only limits download size to client / does not reduce the documents-read-quota charge (https://firebase.google.com/docs/reference/js/firebase.database.Query )