Firebase Admin SDK- get doc IDs

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 inside docSnapshot.

(quote from CBDeveloper on Dec 2, 2020, firebase - Get only collection IDs from Cloud Firestore in one read count - Stack Overflow)

Other Referenced Reading:

1 Like

To any who may read this question later, this was answered by Dmitriy (an engineer at Retool).

Retool has a Beta feature that will allow you to write JS against the SDK directly in Retool.
The documentation and instructions are here: https://docs.retool.com/docs/firebase-raw-queries-beta

Thanks, Matt.

If anyone viewing this is interested in trying out this beta feature, feel free to email me directly dmitriy at retool and I’ll get you set up!

1 Like

Hi dmitry,
I'm very interested in beta access, especially for Timestamp date but I cannot find any contact email, can you help me ?
Thanks in advance!

Hey @Safetrooper!

If you write in to support directly through the in-app chat we can turn on the Firebase raw query beta flag for your org :slightly_smiling_face: