How do I check if a firestore document exists without retrieving it? Either retrieve the list of keys or go doc by doc, I know all the key names Iām checking for. But if I retrieve the entire collection it takes too long because each has a lot of data. Using python 3.9
Asked
Active
Viewed 247 times
0
-
Are you using Firebase Admin SDK or any client? ā Dharmaraj Aug 01 '21 at 17:21
1 Answers
0
You need to retrieve the document to check if it exists even if you know the key and it will cost you a read.
Although if you are using Admin SDK then you can use projections so the data you fetch will be a single field or the document IDs only as mentioned in this answer which might help you save some bandwidth.

Dharmaraj
- 47,845
- 8
- 52
- 84
-
I'm not seeing how to get just the document ids using the admin sdk. When I go to the python docs it basically just redirects me to the vanilla firestore client. Should I be looking at the firebase_admin.db module? ā user433342 Aug 02 '21 at 02:34
-
@user433342 you are looking for [firestore module](https://firebase.google.com/docs/reference/admin/python/firebase_admin.firestore) When you fetch documents each of them will contain a DocumentReference from where you can get the ID. https://googleapis.dev/python/firestore/latest/document.html#google.cloud.firestore_v1.base_document.BaseDocumentReference.id I'm not sure about python but in NodeJS it's like `doc.ref.id` ā Dharmaraj Aug 02 '21 at 04:32