How to know if document exists in firestore python?
If you're using firebase-admin
:
fs.collection('items').document('item-id').get().exists
True
iff items/item-id
exists.
Alternatively
'item-id' in (d.id for d in fs.collection('items').get())
A much simpler and memory efficient approach:
doc_ref = db.collection('my_collection').document('my_document')
doc = doc_ref.get()
if doc.exists:
logging.info("Found")
else:
logging.info("Not found")
Source