[英]how to delete documents in batch in firestore using python
我的 Firestore 中有一個名為 XYZ 的集合。 其中有 500 個不同領域的文檔。 我必須使用集合中的 where 子句刪除多個文檔。
cred = credentials.Certificate('XXXX')
app = firebase_admin.initialize_app(cred)
db = firestore.Client()
batch = db.batch()
doc_ref = db.collection('collection_name').where(u'month', '==', 07).get()
for doc in doc_ref:
batch.delete(doc)
batch.commit()
我試過這個,但最終出現錯誤
AttributeError: AttributeError: 'DocumentSnapshot' object has no attribute '_document_path'
尋求幫助!
您正在將 DocumentSnapshot 對象傳遞給batch.delete()
,這是不允許的。 您必須改為傳遞 DocumentReference 對象,該對象可以在 DocumentSnapshot 的屬性中找到。
batch.delete(doc.reference)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.