1

The following page discusses how to check if a given document exists in Firestore:

How to know if document exists in firestore python?

But in my case, I need to figure out whether a collection exists or not in Firestore database. And at that point in time when I need to check this in the code, I do not know potential document IDs of a given collection. From the above thread, I saw the following provided by @Nebulastic:

doc_ref = db.collection('my_collection').document('my_document')
doc = doc_ref.get()
if doc.exists:
    logging.info("Found")
else:
    logging.info("Not found")

But how can I check if a collection exists or not without knowing anything about its documents (document names/IDs)?

edn
  • 1,981
  • 3
  • 26
  • 56
  • The strategy is the same no matter which language you use. Query the collection with no filters, limit to one document, make sure you get at one document in the query results. If you don't, the collection doesn't exist because it has no documents. (Collections don't really "exist" - they either contain documents or not.) – Doug Stevenson Nov 27 '21 at 00:01

0 Answers0